Я использую Angular 8 и хочу отключить любые ошибки HTTP в консоли браузера, например:
zone-evergreen.js:2828 POST http://localhost:3000/api/auth/login 401 (Unauthorized)
В моем Error-Interceptor. я использую этот код:
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(
private _tokenService: TokenService,
private _routesService: RoutesService,
private _toastService: ToastService
) { }
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
catchError(err => {
if (err.status === 401 || err.status === 403) {
this._tokenService.logout();
this._routesService.navigateToRoute("login");
}
const error = err.error.message || err.statusText;
this._toastService.showError(error, '');
// return throwError(error);
return EMPTY;
})
);
}
}