繁体   English   中英

订阅 Angular/RxJS 的键和可观察的

[英]subscribe keys of and observable in Angular/RxJS

当我在 angular 中发出 HttpCliente 请求并返回一个可观察对象时,我没有在文档(angular 和 rxjs)中找到这个 awnser,例如:

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;
 
 ...

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM