Skip to content

Fix Fetch response metadata in HTTP errors and transfer cache - #69531

Closed
SkyZeroZx wants to merge 3 commits into
angular:mainfrom
SkyZeroZx:http/redirected-response-type-metadata
Closed

SkyZeroZx wants to merge 3 commits into
angular:mainfrom
SkyZeroZx:http/redirected-response-type-metadata

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

fix(http): handle missing redirected and responseType in HttpErrorResponse

Fixes omission of redirected and responseType from the Fetch API in HttpErrorResponse when the promise fails or when an error occurs while parsing the response body.

refactor(http): support redirected and responseType in transfer cache and testing

Store Fetch API redirected and responseType metadata in the HTTP transfer cache when present, so hydrated HttpResponse instances retain the same values. These fields remain omitted for XHR-based responses where the values are not available.

Extend TestRequest.flush() and TestRequest.error() so HttpTestingController tests can provide redirected and responseType on mock responses.

@pullapprove
pullapprove Bot requested a review from kirjs June 26, 2026 04:30
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: common/http Issues related to HTTP and HTTP Client labels Jun 26, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jun 26, 2026
@JeanMeche

Copy link
Copy Markdown
Member

We can't land a feat commit in a patch version. Wdyt of making the change a refactor ?

Comment thread packages/common/http/src/fetch.ts Outdated

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which use-cases / issues are we fixing with these changes?

@SkyZeroZx

Copy link
Copy Markdown
Contributor Author

Which use-cases / issues are we fixing with these changes?

@alan-agius4
Currently, the first commit[fix(http): handle missing redirected and responseType in HttpErrorResponse] fixes the fact that we never receive redirected and responseType when the request fails for some reason or due to server rejection; currently, it comes as undefined, which doesn't help the user know if they were redirected or what the responseType is.

The second fix addresses the issue of the new properties not being properly tested because TestRequest.flush() and TestRequest.error() are not passing the redirected and responseType properties. Additionally, the same problem would occur in the TransferCache; a user making a request from the server side would likely expect or assume that these properties would be available.

…ponse

Fixes omission of redirected and responseType from the Fetch API in HttpErrorResponse when the promise fails or when an error occurs while parsing the response body.
… and testing

Store Fetch API redirected and responseType metadata in the HTTP transfer cache when present, so hydrated HttpResponse instances retain the same values. These fields remain omitted for XHR-based responses where the values are not available.

Extend TestRequest.flush() and TestRequest.error() so HttpTestingController tests can provide redirected and responseType on mock responses.
@SkyZeroZx
SkyZeroZx force-pushed the http/redirected-response-type-metadata branch from ffd4d7a to ae370b6 Compare June 26, 2026 14:37
@SkyZeroZx SkyZeroZx changed the title Transfer Cache updated with new Fetch Response API options and fixed HttpErrorResponse omissions Fix Fetch response metadata in HTTP errors and transfer cache Jun 26, 2026
@SkyZeroZx
SkyZeroZx requested a review from alan-agius4 June 26, 2026 17:15
@JeanMeche
JeanMeche requested review from JeanMeche and removed request for kirjs July 21, 2026 20:45
@alan-agius4

Copy link
Copy Markdown
Contributor

Thanks for working on this!

After reviewing the changes and the use cases:

  1. For non-2xx responses, FetchBackend already populates redirected and responseType on HttpErrorResponse (and in the await fetchPromise catch block, response is always undefined).
  2. Persisting redirected and responseType in TransferCache increases the serialized TransferState HTML payload for every SSR request when using withFetch() (where redirected and type are always defined), and the server-side Response.type (e.g., basic vs. cors from the Node.js server's perspective) does not necessarily reflect what a browser client request would produce.

Since there isn't a compelling use case that justifies the additional transfer state payload and complexity, I'm going to close this PR. Thanks again for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common/http Issues related to HTTP and HTTP Client detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants