We implemented a custom error-handling in our Angular 4 app, which overrides the default ErrorHandler and shows a modal with the error:
@Injectable()
export class GlobalErrorCatcherService implements ErrorHandler {
constructor(private errorDispatcherService: ErrorDispatcherService) { }
public handleError(error: Error) {
this.errorDispatcherService.dispatchError(error);
}
}
Skipping some steps, we then have a ErrorDisplayService, which gets the informations about the error and shows a NgbModal, which is a Component from the @ng-bootstrap framework:
@Injectable()
export class ErrorDisplayService {
constructor(private modalService: NgbModal) {
}
public showError(errorInformation: ErrorInformation): void {
const options = <NgbModalOptions>{
backdrop: 'static',
keyboard: true
};
const modalRef = this.modalService.open(ErrorDisplayContentComponent, options);
const componentInstance = <ErrorDisplayContentComponent>modalRef.componentInstance;
componentInstance.initialize(errorInformation);
}
}
Unfortunately, this works only half of the time: The expected result is sometimes correct, for example:
But more often than not, what we get is something like that:

All my tinkering didn't work so far and I couldn't pin down the problem. Are there further possibilities around I could try to make this work?
