Skip to content

Commit

Permalink
fix: bigquery exception get reason and message (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
Praful Makani committed Oct 8, 2020
1 parent f36b558 commit d783c3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Expand Up @@ -58,7 +58,12 @@ public BigQueryException(int code, String message, BigQueryError error) {
}

public BigQueryException(List<BigQueryError> errors) {
super(0, null, null, false, RETRYABLE_ERRORS, null);
super(
0,
errors != null ? errors.get(0).getMessage() : null,
errors != null ? errors.get(0).getReason() : null,
true,
RETRYABLE_ERRORS);
this.errors = errors;
}

Expand Down
Expand Up @@ -1475,9 +1475,10 @@ public void testSingleStatementsQueryException() throws InterruptedException {
try {
bigquery.create(JobInfo.of(QueryJobConfiguration.of(invalidQuery))).waitFor();
fail("BigQueryException was expected");
} catch (BigQueryException e) {
BigQueryError error = e.getError();
assertNotNull(error);
} catch (BigQueryException ex) {
assertEquals("invalidQuery", ex.getReason());
assertNotNull(ex.getMessage());
BigQueryError error = ex.getError();
assertEquals("invalidQuery", error.getReason());
assertNotNull(error.getMessage());
}
Expand All @@ -1491,10 +1492,11 @@ public void testMultipleStatementsQueryException() throws InterruptedException {
DATASET, TABLE_ID.getTable(), DATASET, TABLE_ID.getTable());
try {
bigquery.create(JobInfo.of(QueryJobConfiguration.of(invalidQuery))).waitFor();
fail("JobException was expected");
} catch (BigQueryException e) {
BigQueryError error = e.getError();
assertNotNull(error);
fail("BigQueryException was expected");
} catch (BigQueryException ex) {
assertEquals("invalidQuery", ex.getReason());
assertNotNull(ex.getMessage());
BigQueryError error = ex.getError();
assertEquals("invalidQuery", error.getReason());
assertNotNull(error.getMessage());
}
Expand Down

0 comments on commit d783c3a

Please sign in to comment.