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.

zone.js promises returning Unhandled Promise Rejection error even with catch blocks

See original GitHub issue

I am working on an angular environment with zone.js so all the native es6 promises have been over-written by zone-aware promises. I have 2 functions called save() and onSaveCb()

save() calls a function called validate() which gets the error-codes of any of the saved objects already present in the file so it is done in sync.

if hasError() returns true we return Promise.reject() from save() otherwise we send a save request to the backend.

Now, onSaveCb() function is an async/await function which has a try-catch block around save().

Problem:

When Promise is rejected from save() function, I see console log error:

zone.js:682 Unhandled Promise rejection: ; Zone: ; Task: onClick Event ; Value: Error:

I tried a bunch of things with wrapping the function save in a promise and then rejecting it, but i still see the same error

function save() {
   let errorCode = this.validate(); // This is a sync call
   if(errorCode !== 0) { return Promise.reject(errorCode);}
   return https(url).then(function() {return true});
} 

function async onSaveCb() {
   try{
     let response = await this.save();
     alertUI(response);
     } catch (response) {
       alertUI(response);
     }
}

I am not sure why I am getting this message when I have clearly written error handling in the catch block. Any help here would be helpful

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
JiaLiPassioncommented, Sep 5, 2019

@Kanti, sure, I have fixed this one, but it break some cases inside Google, so I am working on to provide an option flag to enable/disable this uncaught promise error feature of zone.js.

3reactions
thw0rtedcommented, Jan 29, 2020

Is there any update on this issue? I’m seeing warnings about promises I actually catch as well (using promise.then(x => { }, err => { })). I don’t want to totally disable Zone’s uncaught promise detection feature – it would be great if it worked! – but I’d like it to stop spuriously telling me I didn’t catch something that is in fact caught.

Read more comments on GitHub >

github_iconTop Results From Across the Web

zone.js promises returning Unhandled Promise Rejection ...
Now, onSaveCb() function is an async/await function which has a try-catch block around save(). Problem: When Promise is rejected from save() ...
Read more >
zone.js promises returning Unhandled Promise ... - GitHub
I am working on an angular environment with zone.js so all the native es6 promises have been over-written by zone-aware promises.
Read more >
Handling those unhandled promise rejections with JS async ...
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was ......
Read more >
Error handling with promises
The promise returned by fetch rejects when it's impossible to make a request. For instance, a remote server is not available, or the...
Read more >
Promise.prototype.catch() - JavaScript - MDN Web Docs
Returns a new Promise . This new promise is always pending when returned, regardless of the current promise's status. It's eventually rejected ......
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