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