Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an ensureError utility to ensure that any values thrown or rejected during application rendering and bootstrapping are properly wrapped as Error instances. This utility is integrated into both CommonEngine and AngularAppEngine, and comprehensive unit tests have been added to verify this behavior. The review feedback suggests enhancing ensureError to extract and preserve the original error message or string representation (such as from an HttpErrorResponse) to improve debuggability, and subsequently updating the unit tests to assert on these specific error messages instead of a generic fallback pattern.
alan-agius4
left a comment
There was a problem hiding this comment.
Overall looks good, just a few minor things.
Also a couple of items outside the current diff:
- In
AngularServerApp.handleRendering()(https://github.com/angular/angular-cli/blob/main/packages/angular/ssr/src/app.ts#L387),controller.error(error)runs inside theReadableStreamafterAngularAppEngine.handle()has resolved, so we should wrap that withensureError(error)as well.RenderMode.Prerenderreturns earlier, so prerender error messages stay unchanged. - Can you add a brief note in the JSDoc for
AngularAppEngine.handle()andAngularNodeAppEngine.handle()mentioning that non-Errorrejections are wrapped in anErrorwith the original value oncause?
|
Thanks! |
alan-agius4
left a comment
There was a problem hiding this comment.
LGTM, thanks for your contribution.
|
@alan-agius4 Can this be backported or not? |
Yes |
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
…g in `CommonEngine`
734474a to
f48986f
Compare
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When an app initializer's
HttpClientcall fails, the bootstrap rejects with theHttpErrorResponse, which is not anError.AngularAppEngine.handle()andCommonEngine.render()pass it on as is. The generatedserver.tshands it to Express with.catch(next), Express reads itsstatusandheaders,res.setHeader()throws, and the request is never answered. The process exits when no process-level handler is installed.Issue Number: #34801
What is the new behavior?
Non-
Errorrejections now arrive as anErrorwith a fixed message and the original value ascause.Errorinstances, including theAbortErrorDOMException, are unchanged. A handler that checkederr instanceof HttpErrorResponsenow finds it onerr.cause, and a rejected plain object such as{ status: 404 }now ends as a 500.Angular reports the original value to the
ErrorHandlerand then rethrows it, andHttpErrorResponsecan't extendError.AngularAppEnginebootstraps the app itself, sorenderApplication()isn't on its path. The wrap is inAngularAppEngine.handle()rather than inrenderAngular(), so it also covers routes extracted at request time, and the build's prerender errors keep the original message.instanceof Erroris deliberate:HttpErrorResponsehas a stringnameandmessage, so an error-like check would let it through.Does this PR introduce a breaking change?
Other information
The zoneless case of
subscribe()without an error callback throws outside the render promise, so it isn't covered here.