-
Notifications
You must be signed in to change notification settings - Fork 67
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
Handle thrown errors in promise callbacks #108
Comments
idea behind this is that you handle the error in the code, though I can see how this might be an interesting option to implement after several people have already suggested it. a PR with some docs and explanation for server-side/client-side handling is very much welcome! |
With the following code my error is launched as I wish: @asyncConnect( [ {
promise: ( { store: { dispatch, getState }, helpers: { redirect } } ) => {
throw new Error('Une erreur par ici !');
}
} ] ) But not with this one: @asyncConnect( [ {
promise: async ( { store: { dispatch, getState }, helpers: { redirect } } ) => {
throw new Error('Une erreur par ici !');
}
} ] ) I wish I could do something like: const redirect = to => {
throw new VError({ name: "RedirectError", info: { to } });
};
loadOnServer(
Object.assign({}, renderProps, { store, helpers: { client, redirect } })
)
.then(() => {
const component = createElement(
Provider,
{ store, key: "provider" },
createElement(ReduxAsyncConnect, renderProps)
);
cb(req, res, next, { store, component });
})
.catch(mountError => {
if (mountError.name === "RedirectError") {
return res.redirect(VError.info(mountError).to);
}
console.error("MOUNT ERROR:", mountError);
next(mountError);
}); Given that all the promises of rejections are ignored, using async/await my throw was not the desired effect. I think we should be free to choose what we want to do with our rejections. |
We ended up using our own |
I need exactly the opposite, I would like a rejected promise to remain a rejected promise and not to turn into a I finnaly did something like, I need to use the const redirect = to => {
throw new VError({ name: "RedirectError", info: { to } });
};
loadOnServer(
Object.assign({}, renderProps, { store, helpers: { client, redirect } })
).then(() => {
/*****/
const reduxConnectState = store.getState().reduxAsyncConnect.loadState;
const redirectError = _.find(reduxConnectState, [
"error.name",
"RedirectError"
]);
if (redirectError) {
throw redirectError.error;
}
/*****/
// ...
}); |
This line of code does not catch errors so instead they get lost in the event loop and the component never gets rendered correctly. Additionally, it's hard to catch and display the error in an isomorphic app.
Something like this would reproduce it:
It should be fixable like this:
The text was updated successfully, but these errors were encountered: