Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda