I would like to have a HTTPInterceptor to handle all Errors. My code looks like this:
return next.handle(req)
.pipe(
catchError((response: any) => {
if (response instanceof HttpErrorResponse) {
if (response.status === 401) {
console.log('error catched';
return empty();
}
}
return throwError(response);
})
);
but when running a code which produces a 401 error
return this.http
.post(`${environment.baseAPIUrl}/identity/login`, { 'user': user, 'pwd': pwd})
.pipe(
tap(res => this.setToken(res)),
shareReplay()
);
the output is like that:
POST http://xyz 401 (Unauthorized)
error catched
so I can handle the error but I can't prevent the error output. What am I doing wrong?
best
Ingmar