HttpInterceptor中的角度Http请求超时

问题描述

我这样处理http请求。我想在两个请求之间等待一段时间。例如客户端发送请求,然后发送另一个请求。在3秒内只能发送一个请求,如果在这3秒内收到另一个请求,则该请求将被取消。

intercept(request: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
    request = request.clone({
        setHeaders: {
            'Authorization': `Bearer ${localStorage.getItem('accesstoken')}`,'Accept-Language': localStorage.getItem('language'),'Content-Type': 'application/json'
        }
    });

    return next.handle(request).pipe(
        timeout(3000),tap(this.handleResponse.bind(this)),catchError((error,caught) => {
            //intercept the respons error and displace it to the console
            this.handleAuthError(error);
            return of(error);
        }) as any) as Observable<HttpEvent<any>>;
}

一个句柄请求时,我使用超时。但这是行不通的。因此欢迎任何建议。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)