角度拦截器出错后无法获取响应头

问题描述

如果出现错误,我想在HttpInterceptor中以角度获取响应头。

我在Interceptor中尝试了以下代码,但在控制台中却为空。

intercept(req: HttpRequest<any>,next: HttpHandler):
    Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> {
    return next.handle(this.addHeader(req,this.getAuthToken())).pipe(
        catchError(error => {
            console.log(error.headers.get('errorCode'));
            console.log(error.headers.get('message'));
            return throwError(error);
        })
    );
}

下面是浏览器的“网络”标签中的响应标头。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)