2
使用fetchApi我发出POST请求端点和捕捉错误是这样的:HTTP请求错误代码429不能被捕获
fetch(new Request(url, {
method: 'POST',
headers: { ...defaultHeaders, ...headers } ,
credentials: 'include',
body: JSON.stringify(body)
})).then(
// handle correct reponse
).catch(
if (err.status === 401) {
// handle error nicely
} else if (err.status === 429) {
// handle error differently
} else {
// handle error yet another way
}
);
虽然如预期的那样处理401错误,当端点与429的响应代码
else if (err.status === 429) {
// handle error differently
}
永远不会执行。
EDIT1:永远不会在429
情况下达到整个Catch这些401个429状态码由JavaScript /浏览器处理方式不同? 如何捕获429错误并按我的方式处理?
在所有执行'catch'?那么你是否调试过'err.status'是否真的是'* 429'? – deceze
捕获在401状态代码的情况下执行,但在429的情况下根本不执行。我知道它确实是429,因为错误记录在浏览器的JS控制台中。 –
好的,所以问题不在于'else if'不匹配,而是'fetch'不会拒绝承诺,对吧? – deceze