Repository navigation
fix(sdk): accept all 2xx responses and validate failures on void methods (#7711) - #7740
Merged
Merged
Conversation
Aias00
approved these changes
Oct 17, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
LGTM. The reordering is the right fix, and the escape hatch is preserved exactly where it should be.
Evidence
- The new order is null → raw
ShenyuResponse→ status check →void/empty-body → decode. The raw response still bypasses validation, which is what the class documents as an escape hatch, andhandlerResponseReturnsRawResponseRegardlessOfStatuspins it withassertSameon a 500. isSuccessfulusesHttpStatus.resolve(status).is2xxSuccessful(), so 201/202 now decode instead of throwing, and 204 with a typed return yieldsnullthrough the existing empty-body branch rather than a separate special case.voidmethods moved after the status check, which is the actual bug in #7711: a 500 was previously reported as a normal completion.HttpStatus.resolvereturning null is handled (treated as failure), so no NPE on exotic codes.- Only the Spring SDK has this handler (
grep handlerResponseacrossshenyu-sdk), so there is no sibling implementation left inconsistent.
Nits
- "Accept all 2xx" is implemented as "resolvable and 2xx", so a vendor code such as 299 would still throw even though it is a success by HTTP semantics. If you meant the literal range,
status >= 200 && status < 300is closer; if you meant the enum, the current code is right — please just say which in the PR body. - A 5xx still surfaces as
HttpClientErrorExceptionrather thanHttpServerErrorException. Pre-existing and changing it would break callers' catch blocks, so leaving it is correct — a comment would stop the next reviewer from "fixing" it. HttpStatus.valueOfon an unresolvable code throwsIllegalArgumentExceptionfrom inside the error path; pre-existing, but it now also applies tovoidmethods, which previously never reached that line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7711.
Summary
The Spring SDK's central response handler has inconsistent status validation: the typed path accepts only
200 OK, so successful201/202/204responses throwHttpClientErrorException; andvoidmethods return before any status check, so a500is reported to the caller as normal completion. The rawShenyuResponsereturn type is an intentional escape hatch and is left untouched.Modifications
HttpStatus.resolve(status).is2xxSuccessful()), then handle the raw-response escape hatch,voidmethods and typed body decoding in that order.voidmethods now throwHttpClientErrorExceptionfor non-2xx responses instead of silently succeeding.204 No Contentyieldsnull.Verifying this change
New tests:
handlerResponseAcceptsAllSuccessfulStatuses(200/201/202 decode, 204 null),handlerResponseThrowsForNonSuccessfulStatusesOnTypedMethods(400/500),handlerResponseValidatesVoidMethods(500 throws, 204 null) andhandlerResponseReturnsRawResponseRegardlessOfStatus(raw response returned as-is on 500).Red-green: the 201 case fails with
HttpClientErrorException: 201 CREATEDand the void-500 case fails with "expected exception, nothing thrown" on the previous code; all pass with the fix.Targeted tests pass:
./mvnw -B -ntp -pl shenyu-sdk/shenyu-sdk-spring test -Dtest=ShenyuClientMethodHandlerTest4/4 green (the pre-existing JRE-gated test is skipped).
Checkstyle passes:
clean.
Notes
No change to request construction or transport status propagation. Unknown status codes still surface as
HttpStatus.valueOf(...)behaviour, as before.