问题描述
我无法正确使用Httpinterceptor,因为我没有获得正确的401错误代码。 我的代码是:-
export class RefreshTokenInterceptor implements HttpInterceptor {
private isRefreshing = false;
private refreshTokenSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor(public refreshService: RefreshService) { }
intercept(request: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
if (this.refreshService.getJwtToken()) {
request = this.addToken(request,this.refreshService.getJwtToken());
}
return next.handle(request).pipe(catchError(error => {
if (error instanceof HttpErrorResponse && error.status === 401) {
return this.handle401Error(request,next);
} else {
return throwError(error);
}
}));
}
但是我在 error.status 中得到0。下面提到我在Angular中遇到的错误。
HttpErrorResponse {headers: HttpHeaders,status: 0,statusText: "UnkNown Error",url: "http://localhost:8084/api/v1/category",ok: false,…}
error: ProgressEvent {isTrusted: true,lengthComputable: false,loaded: 0,total: 0,type: "error",…}
headers: HttpHeaders {normalizednames: Map(0),lazyUpdate: null,headers: Map(0)}
message: "Http failure response for http://localhost:8084/api/v1/category: 0 UnkNown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "UnkNown Error"
url: "http://localhost:8084/api/v1/category"
__proto__: HttpResponseBase
从Rest Client呼叫时。它显示状态401 。响应如下:
请帮助我,以解决此问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)