如何在HttpClient上捕获角度为6的429错误响应?
下面的示例将正确捕获401错误,但对于429,它将反馈一个未知错误。
错误/编辑:飞行前选项检查出现故障。
登录代码:
this.http.post<any>(this._loginUrl, this.loginUserData)
.subscribe(
res => {
console.log(res)
},
err => {
console.log(err);
if (err.status == 401) {
// unauthorized
} else if (err.status == 429) {
// limit reached
} else {
// unknown
}
}
)401响应
HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "Unauthorized", url: "http://localhost:82/api/login", ok: false, …}429响应
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}发布于 2018-09-04 13:05:41
由于您的失败发生在飞行前选项请求上,这很可能意味着响应缺少CORS头(这就是为什么您的状态为0,而不是429)。
https://stackoverflow.com/questions/52166778
复制相似问题