Search code examples
javascriptangularrequesttimeout

Angular 7: How to increase the time of an angular request


I need to increase the request time of the angular app because using slow internet connections timeout happens.

I tried the code below and had an error.

this.http.post(url, body, { headers: headers })
            .timeout(100, this.handleTimeout)
            .map(response =>{
                return response;
            })
            .catch(this.handleErrors);

Property 'timeout' does not exist on type 'Observable'.ts(2339)

Not success using interceptor too

@Injectable()
export class AngularInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req).timeout(5000);
}

Property 'timeout' does not exist on type 'Observable>'.ts(2339)

Thanks


Solution

  • The final solutions that works for me:

    import { timeout} from 'rxjs/operators';
    
    return this.http.get(`${url}`).pipe(
                timeout(1000)
            );
    

    Thanks to all for the help.