Return response body in FeignException from errorReading (#2618)#3415
Open
seonwooj0810 wants to merge 1 commit into
Open
Return response body in FeignException from errorReading (#2618)#3415seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
) FeignException.errorReading passed request.body() and request.headers() into the constructor's responseBody/responseHeaders parameters, so FeignException.responseBody()/contentUTF8()/responseHeaders() exposed the request data instead of the response when a read failure occurred while decoding a response. Read the response body (mirroring errorStatus, tolerating a streamed or already-consumed body) and pass the response headers instead. Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
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 #2618
Problem
FeignException.errorReading(...)builds the exception by passingrequest.body()andrequest.headers()into the constructor parameters namedresponseBody/responseHeaders:As reported in #2618, this means that when an
IOExceptionis thrown while reading/decoding the response (seeInvocationContext.decodeandResponseHandler.handleResponse),FeignException.responseBody()/content()/contentUTF8()/responseHeaders()return the request body and headers instead of the response. The maintainer confirmed in the thread that this looks like a bug.Fix
Read the response body into a
byte[]and pass the response headers, mirroring the existingerrorStatus(...)method. Reading is wrapped in atry/catch (IOException ignored)so a streamed or already-consumed body degrades gracefully to an empty body rather than throwing (consistent witherrorStatus).Test evidence
Strengthened the existing
FeignExceptionTest.canCreateWithRequestAndResponseto assert the content: the exception now carries the response body ("response") rather than the request body ("data"), and exposes the response headers. Before the fix this assertion fails (contentUTF8()returned"data").Verification done: (1) no in-flight PR (
gh pr list --search "responseBody"/"errorReading"empty); (2) the only self-claim is a 2024-11-03 question that never produced a PR (>21 days stale); (3) code-focused change inFeignException.java+ test; (4) confirmed therequest.body()pattern still present on current master; (5) maintainer acknowledged the bug in-thread. Commit is DCO signed-off; google-java-format validation passes.