-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatching an action on error (error handling) #78
Comments
You only need to write middleware and catch errors actions using RegExp const restApiErrorCatcher = ()=> (next)=> (action)=> {
if (/^@@redux-api@.*_error$/.test(action.type)) {
const { error } = action;
error && next(notifs.notifSend({message: error.message, kind: 'danger', dismissAfter: 3000}));
}
return next(action);
} |
Wow, that's much much better indeed, thanks!! |
wvengen
added a commit
to foodcoops/foodsoft-shop
that referenced
this issue
May 25, 2016
btw, its |
Oh, its my fail :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to come up with a clean way to handle errors returned by the API. When a request fails, I'd like to show a notification that removes after a timeout. For my purpose, that means dispatching an action (which is thunk-based to be able to submit the hide-notification action after a timeout, e.g. re-notif).
My current solution is to modify all rest-api actions and add an error-handling callback, making sure to call the original callback if it was supplied. It's ugly (I guess it could be improved a bit, but main points are the need to change all existing actions, and the way in which the callback is hooked).
I've tried others things that didn't work out:
Any suggestions to improve this?
The text was updated successfully, but these errors were encountered: