Skip to content

Commit 88f8c63

Browse files
author
Bingqin Zhou
committed
Use getCode instead of getReason
1 parent 5a8ce72 commit 88f8c63

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/write/row/AdaptiveBigQueryWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private boolean isTableMissingSchema(BigQueryException exception) {
8181
private boolean isTableNotExistedException(BigQueryException exception) {
8282
// If a table does not exist, it will raise a BigQueryException that the input is notFound
8383
// Referring to Google Cloud Error Codes Doc: https://cloud.google.com/bigquery/docs/error-messages?hl=en
84-
return exception.getReason() != null && exception.getReason().equalsIgnoreCase("notFound");
84+
return exception.getCode() == 404;
8585
}
8686

8787
/**

kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/write/row/BigQueryWriterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testAutoCreateTables() {
117117
when(insertAllResponse.getInsertErrors()).thenReturn(emptyMap);
118118

119119
BigQueryException missTableException = mock(BigQueryException.class);
120-
when(missTableException.getReason()).thenReturn("notFound");
120+
when(missTableException.getCode()).thenReturn(404);
121121

122122
when(bigQuery.insertAll(anyObject())).thenThrow(missTableException).thenReturn(insertAllResponse);
123123

@@ -152,7 +152,7 @@ public void testNonAutoCreateTables() {
152152
when(insertAllResponse.getInsertErrors()).thenReturn(emptyMap);
153153

154154
BigQueryException missTableException = mock(BigQueryException.class);
155-
when(missTableException.getReason()).thenReturn("notFound");
155+
when(missTableException.getCode()).thenReturn(404);
156156

157157
when(bigQuery.insertAll(anyObject())).thenThrow(missTableException).thenReturn(insertAllResponse);
158158

0 commit comments

Comments
 (0)