Home > Blockchain >  Why i am getting Promise { <pending> } while calling a function from EJS file in node.js
Why i am getting Promise { <pending> } while calling a function from EJS file in node.js

Time:04-20

Below is my function to return SQL query result.

function getPriorityList(operatorId) {
      try {
        const result = Api.getApisDetail(operatorId);
        return result;
      } catch (error) {
        console.log(error);
      }
    }  

CodePudding user response:

you should wait for promise fulfillment

try this :

async function getPriorityList(operatorId) {
      try {
        const result = await Api.getApisDetail(operatorId);
        return result;
      } catch (error) {
        console.log(error);
      }
    }

CodePudding user response:

It appears that the promise implementation is incorrect in this case. Try something along these lines:

function getPriorityList(operatorId) {
    Api.getApisDetail(operatorId).then((result) =>{
        console.log(result);
        return result;
    }).catch((error)=>{
        return error;
    });
}

The "Api.getApisDetail" function must also return promise in this case.

  • Related