title: Should I throw an error or return a rejected promise inside an async function?
body: <p>I'm working with the promises provided by the <a href="https://aws.amazon.com/sdk-for-node-js/" rel="noreferrer">AWS JS SDK</a>. The gist of what I'm doing when I create an async function that wraps the AWS SDK looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports.myCustomFunction = input =&gt; {
  
      if (badInput) {
          throw new Error('failed') // &lt;-- This is they key line
      }
  
      return sns.createTopic(someParams).promise()
  }
  
  // The caller looks like this:
  myModule.myCustomFunction(someInput).then(result =&gt; {
      // carry on
  })
  .catch(err =&gt; {
      // do something with the error
  })
  </code></pre>
  
  <p>I was approached by someone who said that I should never throw an error inside these kinds of promise-based functions. They suggested returning <code>Promise.reject('failed')</code> instead. To be honest I'm not that well versed in promises yet so their explanation kind of went over my head.</p>