Repository navigation
Conversation
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
There was a problem hiding this comment.
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.
backport of #34802