refluxjs: asyncResult action call gives an "Uncaught (in promise)" error
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”:
var Reflux = require('reflux');
var someActions = Reflux.createActions({
doThis: {
asyncResult: true
},
// ...
});
someActions.doThis.listen(function (arg) {
someAsyncProcess(arg)
.then(this.completed)
.catch(this.failed);
});
// elsewhere in the app:
someActions.doThis(arg);
// -> if someAsyncProcess sends back an error, 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 ?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 21 (1 by maintainers)
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.