【发布时间】:2018-06-23 09:18:33
【问题描述】:
在阅读了有关 http 客户端错误处理的 Angular 文档后,我仍然不明白为什么我没有使用以下代码从服务器捕获 401 错误:
export class interceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('this log is printed on the console!');
return next.handle(request).do(() => (err: any) => {
console.log('this log isn't');
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
console.log('nor this one!');
}
}
});
}
}
在控制台日志上,我也得到了这个:
zone.js:2969 GET http://localhost:8080/test401 ()
core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "OK", url: "http://localhost:8080/test", ok: false, ...}
【问题讨论】:
标签: angular angular6 angular-http-interceptors angular-httpclient