-2

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);
      }
    }  
  • 2
    Does this answer your question? [Why is my asynchronous function returning Promise { } instead of a value?](https://stackoverflow.com/questions/38884522/why-is-my-asynchronous-function-returning-promise-pending-instead-of-a-val) – AKX Apr 19 '22 at 18:20

2 Answers2

0

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);
      }
    }
Mohammad
  • 108
  • 5
  • 1
    This has been answered many times before, please flag questions like these as duplicate instead of posting answers to them, SO should not have tons of different versions of basically the same question, all with slightly different answers, as this makes it hard to keep all relevant information updated and consolidated. – CherryDT Apr 19 '22 at 18:36
0

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.