订阅Angular/RxJS中的和可观察的密钥



我在文档中找不到这个awnser(angular和rxjs(,当我在angular中发出HttpCliente请求时,返回一个可观察的值,例如:

let request = this.http.get(url);
request.subscribe(
{ 
next: data => console.log(data),
error: error => console.log(data)
}
);

疑问是:只有当请求答案是200时,"才会落入"下一个?其他403、400、201等是否会"出错"?

2xx代码被视为有效,并将发出next通知。

任何其他代码都将抛出一个Error


以下代码是从HttpXhrBackend实现中提取的。全代码

...

// ok determines whether the response will be transmitted on the event or
// error channel. Unsuccessful status codes (not 2xx) will always be errors,
// but a successful status code can still result in an error if the user
// asked for JSON data and the body cannot be parsed as such.
let ok = status >= 200 && status < 300;

...

干杯

最新更新