title: Make consecutive axios post API calls with proper error handling
body: <p>I need to write an API which will call one POST API and pass the data received from it to another POST API and then return the data from second API to the user.</p>
  <p>There has to be also proper error handling done so that the API should return error message and not fail when one of the API's does not work</p>
  <p>The code that I have tried is as follows</p>
  <pre><code>listPopularPost: async(req, res) =&gt; {
      let requestUrl = process.env.USER_SERVICE_URL+&quot;/api/&quot;+process.env.API_VERSION+'/story-popular';
      try{
          await axios.post(requestUrl, req.body, requestHeader).then((response) =&gt; {
              if(response.data.success == true){
                  let cmsRequestUrl = process.env.CMS_SERVICE_URL+process.env.API_VERSION+&quot;/story/popular&quot;;
                  let requestParam = {
                      &quot;request&quot; : req.body,
                      &quot;user_params&quot;: response.data.story_ids,
                  }
                  axios.post(cmsRequestUrl, requestParam,requestHeader).then((response) =&gt; {
                      res.status(200).send(response.data);
                  }, (error) =&gt; {
                      res.status(200).send({'success':false,'code':'request_error','message':'error encountered','data':{'error':error}});
                  });
              }
          }, (error) =&gt; {
              res.status(200).send(error);
          });
      }
      catch(err){
          console.log(err)
          res.status(500).send(err);
      } 
  },
  </code></pre>
  <p>But it timesout and does not work. How can I fix this code?</p>