title: How can I use recursion to make consecutive axios calls if the response contains 50 ids?
body: <p>I have a function that cycles through an array of URLs with a page number and I'm expecting the response to contain 50 ids maximum. I'd like to return the ids or increment the page counter until response returns less than 50 ids. The code saved below is two separate parts and the Request function is the section not working correctly.</p>
  
  <p>I'm using axios to call the server, but I get the error: "UnhandledPromiseRejectionWarning" </p>
  
  <pre><code>let urlArr = [
        'https://restapi.com/token=TOKEN_ACCESS&amp;usr=Fred&amp;page=', 
        'https://restapi.com/token=TOKEN_ACCESS&amp;usr=Skip&amp;page='
  ];
  let users = [];
  let promises = [];
  let pageCounter;
  for (var i = 0; i &lt; urlArr.length; i++) {
     pageCounter = 0;
     promises.push(
           users.push(this.Request(urlArr[i], pageCounter))
      )
  }
  Promise.all(promises).then(() =&gt; console.log(users));
  
  Request:(url, pageCounter)=&gt;{
        return axios.get(url+pageCounter).then(response =&gt; {
              let itemCounter = 0;
              let arr = [];    //Not sure if this array is needed
              response.data.forEach((item)=&gt;{
                  itemCounter++;
                  arr.push(item.id);
                  if(itemCounter == 50){ //If counter equals 50 go to next page
                      pageCounter++;
                      return Request(url, pageCounter)
                  }
                  return arr;  //return an array with ids
              });            
          });    
  }
  </code></pre>
  
  <p>I expect the output to be an array filled with ids ex: [1, 2, 3]</p>