-
Notifications
You must be signed in to change notification settings - Fork 189
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
Unhandled promise rejection #75
Comments
Which version are you using? |
3.0.0 |
+1 for answer |
@pathsny @trollknurr The middleware dispatches a rejected action, but this does not actually handle the rejected promise. My suggestion would be to either (a) create a second middleware, following the promise middleware, that globally handles all errors/rejected promises; or (b) handle the rejected promise in the action creator, if you are using thunk middleware. // Example with thunk middleware
export function fooActionCreator() {
return dispatch => dispatch({
type: 'FOO_ACTION',
payload: Promise.reject()
}).catch(...);
} The reason this middleware does not handle the rejection is because it takes responsibility for dispatching actions only. It is designed to avoid swallowing errors. Please let me know if this answers your question! Also, sorry for the delay, but I was engaged with finals at school, relocating to CA for a new job and finishing up other work commitments. |
I respectfully disagree with the design decision.
If you really believe that it's necessary to provide users the option to be able to catch a rejected promise, can I suggest adding an option at middleware choice time to turn this off globally? |
You are right, it is not a practical solution. The more practical solution is to build global handling into a middleware. In my opinion, however, building global handling built into the promise middleware doesn't make sense. Instead, I would refer to my suggestion in the previous comment: "create a second middleware, following the promise middleware, that globally handles all errors/rejected promises."
I'm open to exploring changes the middleware, but I don't have time in my schedule now. Addtionally, I don't believe the proposed change makes sense, so I don't want to invest time into it. If you have time and can make some examples, we can go from there! 🔢
This would give me a better understanding of how you wish to change the middleware. |
@pathsny -- what harm comes from an unhandled promise rejection error? The appropriate actions are updated so the app state can react and remain resilient... but what problem would an error in the console cause? I think the errors being propagated are actually useful for debugging -- rather than the promise middleware eating them up (like it used to -- which was my fault) |
The harm is merely annoyance in development. Unnecessary log spew tends to
|
@pathsny I would suggest implementing the global middleware if you want to avoid the annoyance. I don't find it very productive to consider this an actual issue with the project though. |
I understand. Thanks, I'll look into that
|
i also don't understand why this behaviour was changed, i had to fallback to v2.2.3 where the thrown errors (rejected promises) are handled as expected: IMHO thats the way to go |
@DoubleU23 The current version, as do all versions of the middleware, dispatch the rejected action with |
I have a question about what happens when the payload is a promise that is rejected. I see that the middleware correctly dispatches an event with the _REJECTED suffix.
However, I also see a log entry in the console about an unhandled rejection. This is coming from es6.promise. I dont understand why this is considered unhandled, considering that the middleware has dealt with the promise rejection. Is there something I'm supposed to be doing here?
The text was updated successfully, but these errors were encountered: