question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asyncResult action call gives an "Uncaught (in promise)" error

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kembucocommented, Mar 24, 2015

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.

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).catch(function() { /* prevents "Uncaught (in promise) error */});

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.

0reactions
gippy143commented, Jan 11, 2017

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”, url : “/someUrl/”, dataType : ‘json’, async : false,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise) Error: When called with an action of type
The request is okay and I can see the data when I console.log in the action creator but for some reason the reducer...
Read more >
JavaScript Mapping for Operations - Ice
The AsyncResult object returned by an Ice API call encapsulates the state of the asynchronous invocation. In other Ice language mappings, the AsyncResult...
Read more >
Async/await in TypeScript - LogRocket Blog
It provides an easy interface to read and write promises in a way that makes them appear synchronous. An async/await will always return...
Read more >
Asynchronous programming in Office Add-ins - Microsoft Learn
If your call fails you can use the AsyncResult.error property to access ... API provides the Office.select function to support the promises ......
Read more >
Promises - Error Handling - Beginner JavaScript - Wes Bos
When a promise goes awry, and you want to bail on it, you can call the reject function. ... catching the uncaught promise...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found