title: Using async/await and try/catch to make tiered api calls
body: <p>SO friends!</p>
  
  <p>I need to make a call to an api; if it fails, I need to make a call to same api with different param; if it fails AGAIN, I need to make a call to same api with a third, different param; if it fails finally after that, is an actual error and can bugger out.</p>
  
  <p>Only way I can figure to do this is with nested try/catch statements, ala:</p>
  
  <pre><code>const identityCheck = async (slug) =&gt; {
    let res;
    try {
      res = await Bundle.sdk.find(slug);
    } catch (err) {
      console.log('Fragment didn\'t work ========', slug, err);
  
      try {
        res = await Bundle.sdk.find(`package/${slug}`);
      } catch (e) {
        console.log('Fragment didn\'t work package ========', e);
  
        try {
          res = await Bundle.sdk.find(`${slug}-list`);
        } catch (error) {
          console.log('None of the fragments worked================.', error);
        }
      }
    }
  
    return logResponse(res);
  };
  
  identityCheck('fashion');
  </code></pre>
  
  <p>But seems like there MUST be another simpler way to do this. I tried boiling down into a retry function, but that just ends up being even more code and way less clear:</p>
  
  <pre><code>const identityCheck = (slug) =&gt; {
    const toTry = [
      slug,
      `package/${slug}`,
      `${slug}-list`
    ];
  
    return new Promise((resolve, reject) =&gt; {
      let res;
      let tryValIndex = 0;
  
      const attempt = async () =&gt; {
        try {
          res = await Bundle.sdk.find(toTry[tryValIndex]);
          return resolve(logResponse(res));
        } catch (err) {
          console.log(`toTry ${toTry[tryValIndex]} did not work ========`, slug, err);
  
          if (tryValIndex &gt;= toTry.length) {
            return reject(new Error('Everything is broken forever.'));
          }
  
          tryValIndex++;
          attempt();
        }
      };
  
      attempt();
    });
  };
  </code></pre>
  
  <p>Guidance and opinions appreciated!</p>