Skip to content

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

@utsavkapoor

Description

@utsavkapoor

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

Metadata

Metadata

Assignees

Labels

area: zonesIssues related to zone.js

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions