Skip to content
Permalink
Browse files
fix: bigquery exception get reason and message (#788)
  • Loading branch information
Praful Makani committed Oct 8, 2020
1 parent f36b558 commit d783c3a2baf80da2aa48c6be555904bd3c33bb1a
@@ -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;
}

@@ -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());
}
@@ -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());
}

0 comments on commit d783c3a

Please sign in to comment.