Ryan Nguyen
Ryan Nguyen

Reputation: 71

How do increase angular request timeout

I have a request take about 2-5 minutes but it always break at 30s
Is there any way to increase request timeout or prevent request was canceled automatically with angular 8.x?

Upvotes: 1

Views: 2631

Answers (1)

Avdhoota
Avdhoota

Reputation: 461

You need to use the timeout operator. Since rxjs 5.5.2 you need to use the pipe method with lettable operators. And assuming you are using the HttpClient to make your requests, there is no need for a map(response => response.json()).

Like this:

import { timeout, catchError } from 'rxjs/operators'; import { of } from 'rxjs/observable/of';

http.get('https://example.com') .pipe( timeout(2000), catchError(e => { // do something on a timeout return of(null); }) )

Upvotes: 1

Related Questions