Skip to content

Commit

Permalink
Enrich BQSQLExceptions with a little more information for ALL exceptions
Browse files Browse the repository at this point in the history
Should give more information related to #100
  • Loading branch information
Jonathan Swenson committed Aug 4, 2021
1 parent 9a99300 commit fc7b888
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/starschema/clouddb/jdbc/BQSQLException.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ private static String enrichReason(String reason, Throwable cause) {
if (googleJsonResponseException.getDetails() != null) {
return prefix + googleJsonResponseException.getDetails().getMessage();
}
} else {
return prefix + cause.toString();
}
return reason;
}
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/net/starschema/clouddb/jdbc/BQSQLExceptionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.starschema.clouddb.jdbc;

import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpResponseException;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;

public class BQSQLExceptionTest {

@Test
public void exceptionCauseEnrichmentIOExceptionTest() {
IOException ioException = new IOException("Read timed out!");
BQSQLException exception = new BQSQLException("Oops! Something went wrong:", ioException);

String actualMessage = exception.getMessage();
Assert.assertEquals("Oops! Something went wrong: - java.io.IOException: Read timed out!", actualMessage);
}

@Test
public void exceptionCauseEnrichmentGoogleJsonResponseExceptionTest() {
HttpHeaders headers = new HttpHeaders();
HttpResponseException.Builder builder = new HttpResponseException.Builder(
403,"you can't see this", headers
);
GoogleJsonError error = new GoogleJsonError();
error.setMessage("You don't have access");
GoogleJsonResponseException cause = new GoogleJsonResponseException(builder, error);
BQSQLException exception = new BQSQLException("Oops! Something went wrong:", cause);

String actualMessage = exception.getMessage();
Assert.assertEquals("Oops! Something went wrong: - You don't have access", actualMessage);
}

@Test
public void exceptionCauseEnrichmentOtherRuntimeExceptionTest() {
Exception exception = new RuntimeException("something went horribly wrong");
BQSQLException sqlException = new BQSQLException("Oops! Something went wrong:", exception);

String actualMessage = sqlException.getMessage();
Assert.assertEquals("Oops! Something went wrong: - RuntimeException: something went horribly wrong", actualMessage);
}

}

0 comments on commit fc7b888

Please sign in to comment.