Skip to content

Global async error handler with an override possibility #1406

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

Closed
smolyakoff opened this issue Feb 15, 2016 · 3 comments
Closed

Global async error handler with an override possibility #1406

smolyakoff opened this issue Feb 15, 2016 · 3 comments

Comments

@smolyakoff
Copy link

I'm thinking about error handling in redux. Imagine a situation of handling form submit which can return different errors: 400, 401, 500.
When 400 is returned, I want to show a message in top of the form (override the default behavior).
For other (unhandled) error codes, the default (global) error handler should be invoked (which shows notification toast). Just don't want to duplicate this code for every single action

I dispatch async actions using redux-thunk middleware

// Pseudo code
const action = (dispatch) => {

    const onSuccess = (result) => dispatch({type: 'OPERATION_SUCCESS', payload: resuly});
    const onError = (error) => dispatch({type: 'OPERATION_ERROR', error: true, payload: error});

    return promise.then(onSuccess, onError);

};
dispatch(action);

I can create a reducer which handles all {error: true} actions and show some popup-notification (probably without using redux state, directly invoking some toast.show() method)
But how to determine if this special error was already handled somewhere in the state tree?

@gaearon
Copy link
Contributor

gaearon commented Feb 15, 2016

Hi, thanks for coming by.

Please use StackOverflow for usage questions. This is the only way to ensure the same question doesn’t get asked many times in a row, and that folks who have the same question in the future will be able to find it. (Github search is pretty much useless.)

Sorry we couldn’t answer your question here. Please feel free to post a link to the StackOverflow question, and I’ll be happy to try to answer it.

@gaearon gaearon closed this as completed Feb 15, 2016
@smolyakoff
Copy link
Author

@gaearon, thanks for your attention, posted question on stackoverflow

@sompylasar
Copy link

Looks related: #1400 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants