Nesting promises?

I am looking at a way to try and nest promises. There seems to be an issue where I have two apis that keeping flopping back and forth. What I mean is, when the page loads a api will give me a 200, and the other gives me a 500 error. However, if I refresh the page then the successful api will fail and the other one will be successful. I want so that one api is not called until the other is called first. Here is what I have.

initTable() {
      const hiPromise = new Promise((resolve, reject) => {
        resolve(AHMan.getAppHi())
      });
      
hiPromise.then((values) => {
      console.log("the values here are", values);
      approvalHi = values
      }).

I know this works and gets the values back from my hi api. However, issue is try to nest the promises so that the second promise only happens after the first one. I tried this

initTable() {
      const hiPromise = new Promise((resolve, reject) => {
        resolve(AHMan.getAppHi())
      })
hiPromise.then((values) => {
      console.log("the values here are", values);
      approvalHi= values

      }).then(AHMan.getApprov()).then((approvalValue) => {
        console.log(approvalValue);
        approvalList = approvalValue
      })
    },

However, this doesnt seem to work. Any suggestions?

There is actually a function that will create a table based on the approvalHi. Didnt see I left it out

then(AHMan.getApprov()).then((approvalValue) => {
        console.log(approvalValue);
        approvalList = approvalValue
      })
self.generateManTable(approvalHi)
    },

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.