title: Idiomatically handling pre-conditions with ES6 Promises
body: <p>I am new to ES6 Promises and have been doing research. I have some code executing in NodeJS that does some async work, but I have a few pre-conditions that must be checked first. I'm seeking the <strong>idiomatic best-practice</strong> for dealing with this (if such a thing exists) along with some reasoning. I hope to gain an understanding, as I already have working code.</p>
  
  <p>Consider the following fictional snippet:</p>
  
  <pre><code>function doStuff(data, cb) {
       if (!data) {
           return cb(new Error("Don't be an idiot"));
       }
  
       externalLibrary.doSomethingCallbackAsync(data, cb);
  }
  </code></pre>
  
  <p>Were I to translate this into promise-land, I see two options.</p>
  
  <hr>
  
  <p><strong>Option 1</strong>, I can include the pre-condition in the promise.</p>
  
  <pre><code>function doStuff(data){
      return new Promise((resolve, reject) =&gt; {
          if (!data) {
              return reject(new Error("Don't be an idiot"));
          }
  
          externalLibrary.doSomethingCallbackAsync(data, function(err, newData) {
              if (err) {
                  return reject(err);
              }
              return resolve(newData);
          });
      });
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Option 2</strong>, I can run the pre-condition prior to the promise. I'm not certain I understand the intent of <code>Promise.reject()</code>, but it seems to fit the bill here by allowing me to return an immediately rejected promise.</p>
  
  <pre><code>function doStuff(data){
      if (!data) {
          return Promise.reject(new Error("Don't be an idiot"));
      }
  
      return new Promise((resolve, reject) =&gt; {
          externalLibrary.doSomethingCallbackAsync(data, function(err, newData) {
              if (err) {
                  return reject(err);
              }
              return resolve(newData);
          });
      });
  }
  </code></pre>
  
  <hr>
  
  <p>I prefer <strong>Option 2</strong> for readability reasons, but I don't fully understand <code>Promise.reject()</code> and I am concerned that <strong>Option 2</strong> is misusing it. Just to reiterate, I am looking for a best-practice solution.</p>