Error Handler Service 'insider/client' exceptions (of type 'Error') not working when lazy loaded by parent application

This issue has been tracked since 2022-09-20.

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

We have multiple engineering groups working independently building Angular modules (NgModules). We keep these modules entirely independent and self-sufficient and, as such, have their own ErrorHandler overrides. The modules are route lazy loaded as needed into parent apps that require their functionality. Note, although not relevant, the modules are federated (see webpack) and are lazy loaded from other machines. But, for now, we don't believe their federation is the root cause of the issue.

The ErrorHandlers work fine and catch insider/client 'Error's when running in their own standalone apps. However, when loaded into the parent app which DOES NOT OVERRIDE their ErrorHandler's service, the insider Errors are not caught. Important NOTE: The HTTPResponse/HttpErrorResponse, errors (ie outsider/server errors) ARE caught since each independent module calls their overridden ErrorHandler actively via the standard interceptor model-unike the insider/client errors that are called by Angular.

However, when we add an ErrorHandler to the parent, the insider/client Error exceptions do start getting called. Which subverts the modularity required and separation of concerns of our modules. Note, it seems the ErrorHandler must provided at 'root' of any app that requires this feature. Submodules that have that feature are not invoked (except for outsider/server errors).

It 'seems the ErrorHandl

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular 12.2.12

Anything else?

No response

pkozlowski-opensource wrote this answer on 2022-09-20

I think that this issue steams from the assumptions that are not corresponding to the Angular's DI design and implementation:

  • DI tokens (including ErrorHandler) are not scoped to NgModule - instead those are merged / overriden;
  • the expectation is that there is one and only one ErrorHandler in the entire Angular application. We do not intend to support per-NgModule error handlers / more than one ErrorHandler per application.

Closing as not something we intend to support.

momoadeli wrote this answer on 2022-09-20

@pkozlowski-opensource Many thanks. Seems there are architectural obstacles that prohibit this. What is the root rationale ErrorHandler is not provided at module level but at app root once? Can you provide thoughts so we can internally close this thinking and not attempt to write our own?

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-09-30
Star Count 84091
Watcher Count 3064
Fork Count 22233
Issue Count 1203

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date