Closed reederz closed 7 years ago
@reederz I think you should use like this:
const middlewareConfig = {
onError: ({ action, error, next, dispatch }) => {
if (error.response.status === 401) {
return dispatch(AuthActions.logout());
}
let nextAction = {
error,
meta: {
previousAction: action,
},
};
if (action.types && action.types.length === 3) {
nextAction.type = action.types[2];
} else {
nextAction.type = action.type + '_FAIL';
}
next(nextAction);
return nextAction;
}
};
@huytbt thanks. Care to ellaborate on your improvement upon my snippet?
In any case, both of these snippets seem like workarounds. To me, it seems like it would be better handled with a response error interceptor. We would just need an option for NOT handling an error but, instead, propagating it so that it could be handled by reducers.
I am going to close this issue as there as been no interaction for over a month. If this still an issue please reopen the issue.
I would like to be able to intercept a response error with a response error interceptor and still get the
${requestAction}_FAIL
action to be triggered. But it seems that the error just gets swallowed up whenever I add such an interceptor. Am I missing something?For the moment, I'm just using
onError
handler like this: