0
我有一點長登錄過程,它依賴於3個API調用,看起來像這樣的時刻:最外層的.catch()適用於所有鏈接/嵌套promisses嗎?
export const authenticationSignIn = (email, password) =>
(dispatch) => {
dispatch({ type: AUTHENTICATION_REQUEST });
apiAccountStatus(email, password)
.then(({ data }) => {
const status = data.status;
if (status === 'ACCOUNT_CREATED') {
apiSignIn(email, password)
.then(({ data: sessionData }) => {
apiIndexAccounts()
.then(({ data: accountsData }) => {
dispatch({ type: AUTHENTICATION_SUCCESS });
window.router.transitionTo('/dashboard/home');
});
});
} else if (status === 'SOMETHING ELSE') {
// TODO: HANDLE SOMETHING ELSE
}
})
.catch(({ response }) => {
dispatch({ type: AUTHENTICATION_FAILURE });
dispatch(notificationShow('ERROR', response.data.type));
});
};
正如你可以看到這個功能是安靜冗長,但每個嵌套API調用依賴於數據從前一個返回,我試圖儘可能清理它(調度位是特定的,但這些基本上是火的任何傳遞)。最後你會看到一條catch
聲明,我的問題是這個聲明是否適用於所有的promisses或只有apiAccountStatus
?