Angular 角度-无法读取catchError中的www身份验证标头

Angular 角度-无法读取catchError中的www身份验证标头,angular,oauth-2.0,api-authorization,Angular,Oauth 2.0,Api Authorization,我正在尝试读取401响应的www authenticate头,以便触发令牌刷新并将请求再次发送到API。但是,我似乎无法从错误响应中读取标题。下面是角度代码。其他试图刷新访问令牌的人是否面临此问题 const headers = new HttpHeaders({ 'Content-Type': 'application/json', Authorization: 'bearer ' + this.accessToken }); const httpCall = this

我正在尝试读取401响应的www authenticate头,以便触发令牌刷新并将请求再次发送到API。但是,我似乎无法从错误响应中读取标题。下面是角度代码。其他试图刷新访问令牌的人是否面临此问题

const headers = new HttpHeaders({
    'Content-Type':  'application/json',
    Authorization: 'bearer ' + this.accessToken
  });

const httpCall = this.http.get<T>(getUrl, { headers: headers, observe : 'response'});
return httpCall
  .pipe(
    map(resp => {
        console.log(resp);
        return resp.body;
    }),
    catchError((err: HttpResponse<T>, resp) => {
      console.log(err.headers.get('www-authenticate'));
      console.error(err);
      return of(null);
    })
);
const headers=新的HttpHeaders({
“内容类型”:“应用程序/json”,
授权:“承载人”+此.accessToken
});
constHttpCall=this.http.get(getUrl,{headers:headers,注意:'response'});
返回httpCall
.烟斗(
映射(resp=>{
控制台日志(resp);
返回相应的主体;
}),
catchError((err:HttpResponse,resp)=>{
log(err.headers.get('www-authenticate');
控制台错误(err);
返回(空);
})
);

任何帮助都是有用的。谢谢。

在互联网上进一步搜索后,找到了此链接。显然,虽然默认情况下会传递某些头,但我必须在API中显式启用某些响应头。在我的API中启用了WWW身份验证标头,并且能够在代码中读取它