我正在尝试处理应用程序中的发布错误。我正在使用redux-thunk进行异步操作。在成功方法中,它工作得很好,但是我无法设法捕获错误并向表单抛出错误。实际上,它调度我自己的动作,即loginFailed
动作。
formOnSubmitHandler = event => {
// some codes here...
const { values } = this.props.form;
const { from } = this.props.location.state || { from: { pathname: HOME } };
this.props.userLogin(values, from);
// some codes here...
};
这是我的用户登录redux-thunk操作:
export const userLogin = user => {
return dispatch => {
dispatch(loginRequested());
return identityApi
.post(AUTH_SIGN_IN, user)
.then(response => {
if (response.data.isSuccess) {
const {
accessToken,
refreshToken,
expires,
email,
name,
surname,
id,
phoneNumber,
isInformed
} = response.data.data;
dispatch(
loginSucceed({
currentUser: {
id,
name,
surname,
email,
phoneNumber,
isInformed
}
})
);
dispatch(
setToken({
accessToken,
refreshToken,
expires
})
);
}
})
.catch(err => {
dispatch(loginFailed(err.response.data.error.message)); // it is working
throw new SubmissionError({
_error: err.response.data.error.message
});
});
};
};