Skip to content

Commit

Permalink
moved duplicate exceptions to one function (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
samupra authored and dguy committed Oct 18, 2017
1 parent a612d26 commit e5be386
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public QueryStream(Response response) {
@Override
public boolean hasNext() {
if (closed) {
throw new IllegalStateException("Cannot call hasNext() once closed");
throw closedIllegalStateException("hasNext()");
}

if (bufferedRow != null) {
Expand All @@ -197,7 +197,7 @@ public boolean hasNext() {
@Override
public StreamedRow next() {
if (closed) {
throw new IllegalStateException("Cannot call next() once closed");
throw closedIllegalStateException("next()");
}

if (!hasNext()) {
Expand All @@ -212,13 +212,18 @@ public StreamedRow next() {
@Override
public void close() {
if (closed) {
throw new IllegalStateException("Cannot call close() when already closed");
throw closedIllegalStateException("close()");
}

closed = true;
responseScanner.close();
response.close();
}

private IllegalStateException closedIllegalStateException(String methodName) {
return new IllegalStateException("Cannot call " + methodName + " when QueryStream is closed");
}

}

public Map<String, Object> getLocalProperties() {
Expand Down

0 comments on commit e5be386

Please sign in to comment.