Olá Matheus, beleza e você? Segue os códigos abaixo:
NegociacaoController
@throttle()
importaDados(){
this._service.obterNegociacoes((res: Response) => {
if (!res.ok)
throw new Error(res.statusText);
return res;
})
.then(negociacoes => {
negociacoes.forEach(negociacao => this._negociacoes.adiciona(negociacao));
this._negociacoesView.update(this._negociacoes);
})
.catch((err: Error) => {
this._mensagemView.update('Não foi possível importar os dados.');
console.log(err.message);
});
}
NegociacaoService
obterNegociacoes(handler: Function): Promise<Negociacao[]> {
return fetch('http://localhost:8080/dados')
.then(res => handler(res))
.then(res => res.json())
.then((dados: NegociacaoParcial[]) =>
dados
.map(dado => new Negociacao(new Date(), dado.vezes, dado.montante))
);
// .catch(err => console.log(err.message));
}
E no console, não mostra erro nenhum!