Skip to content

[Backport 20.3.X] fix(@angular/ssr): wrap non-Error values thrown while rendering - #34806

Open
SkyZeroZx wants to merge 2 commits into
angular:20.3.xfrom
SkyZeroZx:fix/ssr-non-error-render-rejection-20.3.x
Open

SkyZeroZx wants to merge 2 commits into
angular:20.3.xfrom
SkyZeroZx:fix/ssr-non-error-render-rejection-20.3.x

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

backport of #34802

A value such as the `HttpErrorResponse` of a failed request in an app
initializer was passed to the server as is, where Express reads its
`status` and `headers`. This could leave the request unanswered or
terminate the server process. `AngularAppEngine` now wraps it in an
`Error`.

Fixes angular#34801
…ommonEngine`

`CommonEngine.render()` now also rejects with an `Error` when the
application throws another value, such as an `HttpErrorResponse`.

Fixes angular#34801

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a utility ensureError to ensure that any values thrown or rejected during request handling or application rendering are properly wrapped in an Error instance (with the original value as the cause) before being passed to server frameworks. This prevents unexpected behaviors in frameworks like Express or Fastify when non-Error values (such as HttpErrorResponse) are thrown. The changes apply this utility across CommonEngine, AngularAppEngine, and AngularServerApp's response stream, accompanied by comprehensive unit and integration tests. A review comment highlights a potential issue in AngularServerApp where a client disconnection or request abortion during rendering could cancel the ReadableStream. This would cause controller.error(), controller.enqueue(), or controller.close() to throw a TypeError inside the async start function, leading to an unhandled promise rejection. It is recommended to track the stream's cancellation state and safely handle errors.

Comment thread packages/angular/ssr/src/app.ts Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant