我正在调用的一个 BACKEND API 的获取请求已超过 2 分钟。我正在尝试使用 Angular Http 拦截器来处理这个"timeout": 360000
问题。当我在 proxy.config 中添加时,我的问题在一定程度上解决了。但有时它仍然会失败。这是我的拦截器类。
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout');
@Injectable()
export class DashboardInterceptor implements HttpInterceptor {
constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const timeoutValue = req.headers.get('timeout') || this.defaultTimeout;
const timeoutValueNumeric = Number(timeoutValue);
return next.handle(req).pipe(timeout(timeoutValueNumeric));
}
}
由于它失败了,我试图在通话中发送标头。但它不允许。
getInfo(headers: new HttpHeaders({ timeout: `${360000}` }), params: any[]) {
return this.apiService.get(environment.rm_url + 'rm-analytics-api/dashboard/txn-info', headers, params).pipe(
timeout(360000),
catchError(error => {
console.log('Response error!');
return of({ error});
}
));
}
我将此添加到dashboard.module.ts
providers:[ [DashboardServiceHandler, [{ provide: HTTP_INTERCEPTORS, useClass: DashboardInterceptor, multi: true }],
[{ provide: DEFAULT_TIMEOUT, useValue: 360000 }]]
我也将它添加到 proxy.config 中。
"secure": false,
"timeout": 360000,
我该如何解决这个问题?