After a long search I keep getting the same answer that this seems to be correct:
intercept(request: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
return next.handle(request).catch(errorResponse => {
const status = errorResponse.status;
if (status === 401) { this.matDialog.open(UserDialogComponent); }
return Observable.throw(status);
});
}
This however gives the following error:
ERROR Error: Uncaught (in promise): 401 at S (polyfills.8847e333380b2b4c3385.bundle.js:1) ...
Besides the:
polyfills.8847e333380b2b4c3385.bundle.js:1 GET http://localhost:8080/users/auth 401 (Unauthorized)
error.
The 401 is intentional to test my error handling.
Is this the expected and only handling of Http errors with interceptors in Angular, or can I catch this error somehow?
Many thanks in advance.