Skip to content
Advertisement

resolve and reject issue using node js

  • Is this possible way to return resolve or reject message from one function to another?

  • As I am writing to pass resolve message in postman whenever my task is completed or reject message when there is some error

  • But after after writing return it still not returning the resolve message or reject message inside Postman

any idea how this can be resolve?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

There are few things I would like to mention.

When you create a promise, it should have resolve() and reject() inside it.

for ex-

JavaScript

In the method which you have written, You have applied .then() method to non promise object. You have to complete the promise block first with resolve() and reject() inside it. Then you can return that promise from a function, use it in async function Or apply .then() block on it.

Also you don’t need to add return statement to resolve() and reject() statement. The system will take care of it.

You can also use try catch block inside a promise. Its better to write reject() statement in catch block, if anything goes wrong.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement