Skip to content

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

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

SkyZeroZx wants to merge 2 commits into
angular:21.2.xfrom
SkyZeroZx:fix/ssr-non-error-render-rejection-21.2.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 function ensureError to guarantee that any value thrown or rejected during application rendering or request handling is wrapped in a standard Error instance, preventing unexpected behavior in server frameworks when non-Error values are thrown. These changes are applied across CommonEngine, AngularAppEngine, and the response stream controller in AngularServerApp, alongside comprehensive tests. Feedback on the changes highlights a potential issue in AngularServerApp where calling controller.error() inside the stream's catch block could throw a TypeError if the controller is already closed or cancelled, which could lead to an unhandled promise rejection. It is recommended to wrap controller.error in a nested try/catch block to safely handle this scenario.

Comment thread packages/angular/ssr/src/app.ts Resolved
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: lts This PR is targeting a version currently in long-term support labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr target: lts This PR is targeting a version currently in long-term support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants