简体   繁体   English

如何增加 angular 请求超时

[英]How do increase angular request timeout

I have a request take about 2-5 minutes but it always break at 30s我有一个请求大约需要 2-5 分钟,但它总是在 30 秒时中断
Is there any way to increase request timeout or prevent request was canceled automatically with angular 8.x?有什么方法可以增加请求超时或防止请求被 angular 8.x 自动取消?

You need to use the timeout operator.您需要使用超时运算符。 Since rxjs 5.5.2 you need to use the pipe method with lettable operators.自 rxjs 5.5.2 起,您需要将 pipe 方法与 lettable 运算符一起使用。 And assuming you are using the HttpClient to make your requests, there is no need for a map(response => response.json()).假设您使用 HttpClient 发出请求,则不需要 map(response => response.json())。

Like this:像这样:

import { timeout, catchError } from 'rxjs/operators';从'rxjs/operators'导入{超时,catchError}; import { of } from 'rxjs/observable/of';从 'rxjs/observable/of' 导入 { of };

http.get(' https://example.com ').pipe( timeout(2000), catchError(e => { // do something on a timeout return of(null); }) ) http.get(' https://example.com ').pipe( timeout(2000), catchError(e => {}) 在超时时做一些事情))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM