我正在尝试使用一个值来检查拦截器中的令牌是否已过期。令牌过期值出现在响应标头中。 screenshot of response header
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const reqWithCredentials = req.clone({withCredentials: true});
return next.handle(reqWithCredentials)
.pipe(map(resp => {
// on Response
if (resp instanceof HttpResponse) {
// Do whatever you want with the response.
return resp;
}
}),
catchError(error => {
if (error instanceof HttpErrorResponse) {
if (error.status === this._appConstant.ErrorCodes.Unauthorized || error.status === this._appConstant.ErrorCodes.Forbidden) {
if (error.headers.has('Token-Expired')) {
this.router.navigate(["/tokenexpired"]);
}
else {
this.router.navigate(["/unauthorized"]);
}
}
else {
return throwError(error);
}
}
})
);
}
答案 0 :(得分:0)
int