Skip to content

fix: keep Response API when omitting request data - #1736

Merged
olleolleolle merged 1 commit into
lostisland:mainfrom
yykamei:fix-error-response-on-complete
Nov 13, 2026
Merged

olleolleolle merged 1 commit into
lostisland:mainfrom
yykamei:fix-error-response-on-complete

Conversation

@yykamei

@yykamei yykamei commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Purpose

Keep Faraday::Error#response compatible with Faraday::Response consumers when request data is omitted, including callers that use #on_complete.

Background

#1729 broadened include_request: false to errors raised by other middleware but represented sanitized responses as Hashes. This causes NoMethodError when middleware expects a Response; return a fresh Response whose Env copies only status, response headers, and response body. Request fields, custom members, and the original Response backlink are not retained, so the request-data protection from #1729 remains intact.

Out of Scope

The Hash response values generated directly by RaiseError for 4xx/5xx responses remain unchanged. Pre-existing issues involving wrapped JSON parser messages and late-finished Responses are also unchanged.

Operational Notes

For finished Responses, #body now prefers the explicit response body when present, including for nil-status responses and false bodies. The legacy Env#body fallback remains for statusless middleware that does not populate response_body.

Sanitizing flagged Responses as Hashes broke middleware calling
on_complete, including retry flows. Build a fresh Response from response
fields alone so request data stays hidden without losing that API.

Prefer explicit response bodies for nil-status Responses while retaining
the legacy body fallback. Keep RaiseError's existing Hash responses
unchanged.

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this persuasive!

@olleolleolle
olleolleolle merged commit 565a149 into lostisland:main Nov 13, 2026
16 checks passed
@yykamei
yykamei deleted the fix-error-response-on-complete branch November 13, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants