【发布时间】:2017-05-20 01:20:22
【问题描述】:
我很难理解在 http 调用出现错误时的行为。
目标是根据服务器在 403 或 400 响应时返回的错误消息有不同的行为。
使用 Chrome 网络时,我可以看到消息
但是,当我对错误进行 console.log 时,我得到的只是正文中的 ProgressEvent 对象。
有问题的代码非常简单,200 处理得很好,返回的 json 是可访问的。
this.service.myFunction(this.email).subscribe(
auth => console.log(auth), // works fine
error => console.log(error)
);
在实际调用中,我也尝试了 catch,但没有成功。
this.myFunction.get(url).map(res => res.json())
.catch( (err: Response) => Observable.throw(err.json()) ); // throw the error, which is also the object described above
你知道我做错了什么吗?
谢谢
【问题讨论】: