Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
angular 2 observable timeout second parameter type

I am currently trying to make timeout() method of Angular 2 Observable work properly, but in all tutorials there is similair code, where the second argument of timeout() method is a simple Error:

return this.http.get('http://...')
                .timeout(2000, new Error('Timeout exceeded'));

But when I copy this code, TypeScript says that the second argument has invalid type and expects to see smth which implements interface IScheduler.

One of the ways to solve the problem is to make new class which implements IScheduler interface, but it has functionality I am not familiar with (now() method and Tasks).

Does anyone know, should I do it in this way or are there another ways to make things work? And what if instead of error I want to place some callback function?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

timeout does not take an Error as a parameter. If a timeout occurs it will throw a TimeoutError.

If you want to throw a particular type of error, you could use the timeoutWith operator to do something like this:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/timeoutWith';

return this.http
  .get('http://...')
  .timeoutWith(2000, Observable.throw(new Error('Boom!')));
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!