Skip to content

fix(http): propagate plain errors when parsing fails#62765

Closed
sbarfurth wants to merge 1 commit intoangular:mainfrom
sbarfurth:sbarfurth/plain-error-forward
Closed

fix(http): propagate plain errors when parsing fails#62765
sbarfurth wants to merge 1 commit intoangular:mainfrom
sbarfurth:sbarfurth/plain-error-forward

Conversation

@sbarfurth
Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

When the responseType is set to json and the fetch backend is active, the response body will always be parsed as JSON, regardless of whether it is a success or error response. However, it's not uncommon for successful requests to return one type and errors to return another type. The current implementation will fail parsing in this case and forward only the resulting SyntaxError on HttpErrorResponse.error. This obfuscates the source error body entirely to downstream response consumers.

Issue Number: N/A

What is the new behavior?

The fetch backend now propagates the plain body when parsing the body fails. This replicates the behavior of the XHR backend introduced in #19773.

Propagating the plain error allows downstream error consumers to reason about the error body and decide how to parse it depending on application needs.

Does this PR introduce a breaking change?

I'm unsure if you'd consider this breaking. The previous implementation exposed relatively useless SyntaxError, but people may be relying on these for some reason?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from mmalerba July 23, 2025 15:10
@angular-robot angular-robot bot added the area: common Issues related to APIs in the @angular/common package label Jul 23, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 23, 2025
@JeanMeche
Copy link
Copy Markdown
Member

Could you please reword the commit, the scope should be http.

The fetch backend now propagates the plain body when parsing the body fails.
This replicates the behavior of the XHR backend introduced in angular#19773.

The current state completely obfuscates errors of the "wrong" response type.
However, it's not uncommon for successful requests to return one type and
errors to return another type. Propagating the plain error allows downstream
error consumers to reason about the error body and decide how to parse it
depending on application needs.
@sbarfurth sbarfurth force-pushed the sbarfurth/plain-error-forward branch from 9f20569 to 646d4c1 Compare July 23, 2025 15:26
@sbarfurth sbarfurth changed the title fix(common): propagate plain errors when parsing fails fix(http): propagate plain errors when parsing fails Jul 23, 2025
@angular-robot angular-robot bot added the area: common/http Issues related to HTTP and HTTP Client label Jul 23, 2025
@sbarfurth
Copy link
Copy Markdown
Contributor Author

Could you please reword the commit, the scope should be http.

Done, sorry about that.

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jul 23, 2025
@thePunderWoman thePunderWoman added the target: patch This PR is targeted for the next patch release label Jul 24, 2025
thePunderWoman pushed a commit that referenced this pull request Jul 24, 2025
The fetch backend now propagates the plain body when parsing the body fails.
This replicates the behavior of the XHR backend introduced in #19773.

The current state completely obfuscates errors of the "wrong" response type.
However, it's not uncommon for successful requests to return one type and
errors to return another type. Propagating the plain error allows downstream
error consumers to reason about the error body and decide how to parse it
depending on application needs.

PR Close #62765
@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 1b73c23.

The changes were merged into the following branches: main, 20.1.x

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client area: common Issues related to APIs in the @angular/common package target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants