我在檔案(angular 和 rxjs)中找不到這個 awnser,當我在 angular 中發出 HttpCliente 請求并回傳一個 observable 時,例如:
let request = this.http.get(url);
request.subscribe(
{
next: data => console.log(data),
error: error => console.log(data)
}
);
疑問:只有在請求答案為 200 時才會“落入”下一個?其他 403、400、201 等是否會“陷入”錯誤?
uj5u.com熱心網友回復:
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;
...
干杯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/450147.html
上一篇:批準PayPal訂單但服務器端
下一篇:as和let之間的異步管道區別
