我真的很奇怪。由於某種原因,我的put
在我的catch
塊中沒有在下面執行。這裏是我的傳奇:Redux-saga產量put()in catch block not executed
function* postLoginFormSaga(action) {
let response;
try {
// Data from emitting login action
response = yield call(AuthenticationApi.login, action.formData);
yield put(createLoginSucceedAction());
yield put(push('/dashboard/summary'));
} catch (e) {
console.log(e);
yield put(createLoginFailAction(response))
}
}
我的API調用,它有一個自定義的中間件來處理非2XX
迴應:
static login = (formData) => {
return fetch('/api/login', {
method: 'POST',
body: formData,
credentials: 'same-origin'
}).then(handleFetchErrorMiddleWare)
.then(r => r.json())
};
凡中間件功能是檢查response
的ok
屬性的簡單功能object:
export function handleFetchErrorMiddleWare(response) {
if (!response.ok){
throw Error(response.status)
}
return response
}
中間件工作正常,因爲我可以看到console.log(e)
wh的輸出恩拋出一個異常,但yield put(createLoginFailAction(response))
沒有被髮出... 見下文:
任何想法?謝謝
是否正確'yield put(createLoginFailAction(response))'? 'response'在這裏是'undefined'。 –
在'createLoginFailAction'函數中可能有錯誤,那是什麼樣的? – erikvold