Angular 2 Http Timeout

I am having trouble sending a custom error message when HTTP timeout.

Here is a simple example:

return this._http.get(url).timeout(5000, new Error("Error message"));

I saw that everyone is using a new error ("Error Message") , but I get an error message:

The error function expects the type Scheduler. I get this error: An argument of type “Error” is not assigned to a parameter of type “Scheduler”. The SchedulerAction property is missing from the Error type

+4
source share
3 answers

rxjs 4 . rxjs 5 timeout :

  • due: number |
  • scheduler: IScheduler ( , Observable )

, - :

return this._http.get(url)
 .timeout(5000)
 .catch(err => {

   if (err.name !== "TimeoutError") {
      return Observable.throw("Timeout has occurred");
   }

   return Observable.throw(err);

});
+9

timeoutWith:

return this._http.get(url).timeoutWith(5000, Observable.throw(new Error("Error message")));
+2

Starting with version rc.5, the timeout no longer accepts the errorToSend argument.

https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#500-rc5-2016-12-07

0
source

Source: https://habr.com/ru/post/1665742/


All Articles