0

I would like to provide a Custom ErrorHandler to our angular project when it is build (using angular-cli) in the production environment.

I've tried what's been said here with no success.

To not leave you without a code sample, this is what I've ended up with:

let providers: Provider[] = [
    ...
];

if(environment.production) {
    providers.push({ provide: ErrorHandler, useClass: MyErrorHandler });
}

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        ...
    ],
    bootstrap: [AppComponent],
    providers: providers
})

But building (or serving) the app:

$ ng build --prod
$ ng serve --prod

Does not include this error handler.

How should I proceed to do so ?

Community
  • 1
  • 1
RVandersteen
  • 2,067
  • 2
  • 25
  • 46
  • What exactly does "no success" mean with the approach explained in the question you linked to? – Günter Zöchbauer May 08 '17 at 17:44
  • Well, in the link I have to provide a service. Which I don't have in the other case. I only need to provide something in production – RVandersteen May 08 '17 at 17:45
  • You can provide the default `ErrorHandler` during development and the custom one in production. – Günter Zöchbauer May 08 '17 at 17:47
  • I kept bouncing on ERROR in Error encountered resolving symbol values statically. Function calls are not supported. – RVandersteen May 08 '17 at 17:59
  • That doesn't seem to be related to providing something only in production or providing a custom error handler. Please post the code that causes the error and the exact error message. – Günter Zöchbauer May 08 '17 at 18:01
  • I found the error, is related to https://github.com/angular/angular-cli/issues/3707. I added my solution to http://stackoverflow.com/questions/39942118/how-to-inject-different-service-based-on-certain-build-environment-in-angular2/43854424#43854424 – RVandersteen May 08 '17 at 18:03

0 Answers0