-
Notifications
You must be signed in to change notification settings - Fork 329
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
asyncResult action call gives an "Uncaught (in promise)" error #296
Comments
I'm having this issue as well. Below are my various experiments let ProjectActions = Reflux.createActions({
'update': {
asyncResult: true
}
});
ProjectActions.update.listen((projectModel, organizationSlug) => {
if (false) {
ProjectActions.update.completed();
} else {
ProjectActions.update.failed();
}
});
// "Uncaught (in promise)..." As expected, but just for completeness, swapping However this does work just fine: let ProjectActions = Reflux.createActions({
'update': {
children: ['completed', 'failure']
}
});
ProjectActions.update.listen((projectModel, organizationSlug) => {
if (false) {
ProjectActions.update.completed();
} else {
ProjectActions.update.failure();
}
}); I also get the sense I'm doing something wonky... |
I was running into this as well and it was driving me batty. I'm pretty sure I know what the issue is, but I'm not sure what the correct solution is. However, there is a workaround you can put in your code to at least prevent the error from popping up in the console.
The key bit being that catch there at the end. The problem is that when the "doThis" action is called a promise is setup that listens for "doThis.failed" to be called. Of course, when your "someAsyncProcess" promise gets rejected, the "doThis.failed" gets called as expected. However, that also triggers a reject on the promise that Reflux sets up in the generated function for the action. Because there isn't a catch setup for that, the promise API throws an error. I'm still not quite sure I understand why reject is called when the failed child action is triggered as it seems like it should work the other way around. I'm sure there is a good reason for it. |
Are you using the latest code? I believe this might have been fixed by #267. |
Yes. I just checked and I have the latest code. From the diff, it looks like PublisherMethods#promise is providing a catch for the promise that is supplied by the caller's async function. However, the issue arises when reject is called on the promise created in the PublisherMethods#triggerPromise function. |
👍 |
I'm having this same issue, would like to see a fix. Let me know if there's anything I can do to help :) |
👍 also experiencing this bug |
Same bug:( |
👍 Same here. Thanks for fixing! |
Having this issue as well. This error doesn't happen in all failed async cases, which is strange. @afrojas's solution worked -- simply rename the "failed" method to "failure" or something else. |
Same problem here. Thanks to @afrojas solution. Working fine. |
I needed const Reflux = require('reflux')
function createAction(promiseFactory) {
const action = Reflux.createAction({ sync: true, children: ['completed', 'failed'] })
if (promiseFactory) {
action.listen((...args) => {
promiseFactory(...args)
.then(res => action.completed(res, ...args))
.catch(res => action.failed(res, ...args))
})
}
return action
} |
Closing in light of #352 |
Thank you @LongLiveCHIEF for your insight on the topic. |
I don't know for certain what the future holds yet, but what I'm working on at the moment is a model that means actions are subscribable and asynchronous by default, which changes the paradigm of "triggering" the response. the reason I closed the issue, is because there is a bug with how the current implementation works, and it doesn't work as intended. It's a big of a design bug, more than a code bug though, so it's not something that can be fixed with same api implementation. (via side-effect/shortcut). Because of how promises are intended to work, it's actually easier just to use promise methods to trigger handling, instead of relying on shortcut methods. |
Allright, thank you for the details. |
So, renaming to something other than 'failed' fixes the issue. But I'm having trouble seeing why the name itself causes the issue. Can someone shed some light on this? I've looked through reflux-core and refluxjs and can't see why the name is important. Thanks |
We are also running into this issue as a result of using listenAndPromise to wire an asyncResult action with completed/failed children to a method that returns a promise. This is already mentioned here but approaches the seem to work I am listing below
As noted elsewhere there seems to be a race condition when NOT using sync: true with the failed child method of an async result. Unless I'm missing something this means that listenAndPromise by default is broken and will subject you to errors in the console unless you add sync: true. I tried and failed to read the PublisherMethods code that seems responsible for this race condition that happens when combining sync: false with asyncResult: true I was unable to clearly understand why the "failed" child action name is significant and causes different behavior for listenAndPromise I am currently using 0.2.8 of reflux. |
Hi All, I was struggling with the same issue but I got it fixed by making minor change. Add async : false in all AJAX get requests. Consider the code below: type : "GET", |
When I call an asyncResult action and when the triggered async process sends back an error (for example: "401 unauthorized"), everything works fine but I get another error in the console: "Uncaught (in promise) ... PublisherMethods.js:168":
Am I doing it wrong, or is there a bug in the asyncResult actions ?
The text was updated successfully, but these errors were encountered: