-
Notifications
You must be signed in to change notification settings - Fork 46
feat: have DatastoreException extend BaseHttpServiceException, convert gRPC status codes to existing Datastore codes #1409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…t gRPC status codes to existing Datastore codes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor things, that may not need to be addressed in this PR (or at all)
GrpcToDatastoreCodeTranslation.grpcCodeToDatastoreStatusCode(gsc.getTransportCode()); | ||
} | ||
|
||
// If there is a gRPC exception in our cause change pull it's error message up to be our |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If there is a gRPC exception in our cause change pull it's error message up to be our | |
// If there is a gRPC exception in our cause, pull it's error message up to be our |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in subsequent commit.
@@ -1316,6 +1319,12 @@ public void testUpdate() { | |||
datastore.delete(ENTITY3.getKey()); | |||
} | |||
|
|||
private void assertDatastoreException( | |||
DatastoreException expected, String reason, int datastoreStatusCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this naming feels backward to me. I interpret expected as the value that is expected to hold in the assertion, not the exception that was expected to be thrown.
May not be worth the hassell, but I prefer the following pattern for asserting exceptions that are expected to be thrown:
DatastoreException datastoreException = org.junit.Assert.assertThrows(DatastoreException.class, () -> datastore.update(ENTITY3));
com.google.common.truth.Truth.assertThat(datastoreException.getReason()).isEqualTo(NOT_FOUND.name());
com.google.common.truth.Truth.assertThat(datastoreException.getCode()).isEqualTo(5);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! I've made these updates.
Building on top of changes in #1400, this PR reverts the updates in #1244 and instead translates gRPC error codes into existing Datastore ones.
This follows the same logic and patterns as in java-storage: https://github.com/googleapis/java-storage/blob/main/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcToHttpStatusCodeTranslation.java