我想知道在第二次尝试后如何返回请求结果。
步骤
为此,我正在使用HttpInterceptor
所以第1、2、3、4步有效,但最后一个不起作用!
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
tap(() => {},
(err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
// display login form
this.displayLoginForm();
// Subscribe event
this.store.select('retry').subscribe((data) => {
if (data) {
const req = request.clone({
setHeaders: {
Authorization: `Bearer ${this.globalDataService.token}`
}
});
// Retry the last request
return next.handle(req).subscribe((data) => {
if (data instanceof HttpResponse) {
// There i am getting the result of the working request
console.log(data.body);
// ???? What to do to get the result in my component var ?
}
});
}
});
}
}
})
);
}