I've a created global error handler like below:
GlobalErrorHandler.ts
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
constructor() { }
async handleError(error) {
//not getting called
}
}
TestService.ts
@Injectable()
export class TestService {
async Test() {
let result = await this.http.get(url).toPromise().catch(e => {
throw e;
});
return result
}
I've a component which calls Test method of TestService. Problem here is that the error thrown by Test method is not getting caught by GlobalErrorHandler. I can just see "Unhandled Promise rejection:" in the developer console.
I've declared GlobalErrorHandler as provider in the app.module.ts. Both services are in the same module, while the component is in another module. I've spent lot of time in research but couldn't find the proper solution.
Any help or suggestion would be great!
Thanks.