-
Notifications
You must be signed in to change notification settings - Fork 107
fix: update exception mapping on HTTP error responses #1570
Conversation
Interprets HTTP error reponse codes as defined by the canonical error code mapping. Not marking as breaking changes as it affects only httpjson that is not GA-ed.
@meltsufin @vam-google ready for review. Check out the PR description for details. |
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.
LGTM.
gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonStatusCodeTest.java
Outdated
Show resolved
Hide resolved
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.
LGTM, but we need to test it with java-compute properly before GA, as it may affect its behavior and retries in particular.
} | ||
return Code.UNKNOWN; |
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.
Is mapping 300s to unknown intentional and canonical behavior here?
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.
Yes, All 3xx's are mapped to UNKNOWN according to go/http-canonical-mapping.
As mentioned in b/205195666, I have conducted multiple tests for this change, whose results seem all good. @vam-google merging this now, but if you want me to do some other tests, just let me know. |
🤖 I have created a release \*beep\* \*boop\* --- ### [2.7.1](https://www.github.com/googleapis/gax-java/compare/v2.7.0...v2.7.1) (2021-12-02) ### Bug Fixes * fix gRPC code conversion ([#1555](https://www.github.com/googleapis/gax-java/issues/1555)) ([09b99d5](https://www.github.com/googleapis/gax-java/commit/09b99d591497b44c3c25b1a54abb0f1cb69d7376)) * pass error message when creating ApiException ([#1556](https://www.github.com/googleapis/gax-java/issues/1556)) ([918ae41](https://www.github.com/googleapis/gax-java/commit/918ae419f84ad5721638ca10eca992333e9f7c3d)) * revert generics syntax change in MockHttpService test utility ([#1574](https://www.github.com/googleapis/gax-java/issues/1574)) ([b629488](https://www.github.com/googleapis/gax-java/commit/b629488ffc7d68158158d9197695158f97229c7b)) * update exception mapping on HTTP error responses ([#1570](https://www.github.com/googleapis/gax-java/issues/1570)) ([8a170d1](https://www.github.com/googleapis/gax-java/commit/8a170d19b42e9b13d4c69dcfbe531d4d4ca69c90)) ### Dependencies * update grpc to 1.42.1 ([#1559](https://www.github.com/googleapis/gax-java/issues/1559)) ([92b7632](https://www.github.com/googleapis/gax-java/commit/92b76325d54604c98c798c489b3a963fdf21a75c)) * upgrade protobuf to 3.19.1 ([#1571](https://www.github.com/googleapis/gax-java/issues/1571)) ([7b354e7](https://www.github.com/googleapis/gax-java/commit/7b354e73b8ce49008bed51076afb255ca5dc68e4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
The HTTP-to-Canonical code conversion (
HttpJsonStatusCode.httpStatusToStatusCode()
) is used only for error situations where a server returns a non-2xx HTTP status code. gax-java surfaces errors in terms ofApiException
s, which are modeled precisely following the canonical status codes (go/canonical-codes). (That is, there's a one-to-one correspondence between the canonical error codes and the Java exceptions.) That's why and the only reason we need to interpret HTTP codes as canonical codes.The previous implementation wasn't following the standardized mapping (go/http-canonical-mapping). Now we are trying to make this consistent across all languages. Therefore, this does introduce a breaking change in terms of which HTTP server response code is surfaced as which Java exception.
However, for the conventional commit message and the PR title, I'm not marking as a breaking change, as gax-httpjson hasn't GA'ed.
b/205195666
Appendix
The locations where the HTTP-to-canonical conversion takes place:
HttpJsonExceptionCallable.onFailure()
: HTTP error status is interpreted as canonical error status (via exception).HttpJsonOperationSnapshot.Builder.setError()
: the builder takes an HTTP code. Note there's no usage ofsetError()
within gax-java. It is supposed to take HTTP code, but for some legacy reason, it treats 0 as a special case to indicate success (which is not ideal).