-
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 rejected promises #104
Comments
I think you can populate your state with something like |
@vpanjganj I was trying to avoid the approach you suggested. I think rendering of the component should not be aware of a data load failure. Duplication of the error handling code at every container component hints at that. |
@yoadsn ,I think if a component (UI) has to visually respond to a data load failure, it is enough reason to include that in the state and implement the behaviour in the component. To address your concern about redundant code to handle data errors; you can use Higher-ordered components to reuse the logic anywhere necessary. |
Thats correct ;) |
If someone is looking for a catch behaviour, you can pull out the error from state and throw if it exists.... something like the following should work. This tosses the first error encountered, but could easily be reworked into aggregating all the errors into an array. loadOnServer({ ...renderProps, store }).then(() => {
const {loadState} = store.getState().reduxAsyncConnect
const err = Object.keys(loadState).reduce((memo, key) => memo || loadState[key].error, null)
if (err) { throw error }
// whatever else
})
.catch(err => {
// a wild error handler appeared!
next(err)
}) I'd much prefer if it automagically went into the catch block myself, but can appreciate the reasoning / breaking changes / potential for multiple errors, etc. for not doing it like that. |
I must be missing something here.
If I return a rejected promise from the loader of a component, nothing seems to work as expected.
On the server side,
loadOnServer
itself is not rejected but rather it continues to resolve the promise and so the component tree gets rendered without the required data. I then get other exceptions due to the missing data which does reject the entire promise. (as expected).On the client side, I am not even sure what to expect - clearly there is no extension point where I can change the routing and redirect to an error page. How should that be handled on the client?
Any insights on this would be great (I was digging in the sources for a while, but I don't think there is any special handling for this situation)
Thanks!!
The text was updated successfully, but these errors were encountered: