title: Multiple promises in Node with error handling
body: <p>How can I avoid nesting-hell with a chain of service calls in Node.js, where I'd like to throw a given error and exit the entire chain in certain instances? Here's an example of the chain:</p>
  
  <ol>
  <li>Load Mongoose object.</li>
  <li>If load fails, <code>res.send(404)</code>; if load succeeds, go to the next <code>then()</code>.</li>
  <li>Call 3rd party API to get some data.</li>
  <li>If API call fails, send proper response (say the proper status code is <code>500</code> just for the sake of this problem)</li>
  <li><p>If API call succeeds, render the page.</p>
  
  <pre><code>SomeMongooseModel.findOne({id:123}).exec()
  .then(function(response)
  {
      // If group is empty, would like to res.send(404) and resolve the 
      // promise immediately.
  })
  .then(function(response)
  {
      // Hit 3rd party API to retrieve data. If there's an issue, return
      // response code of 500 and resolve promise immediately.
  
      // Assuming the API call was a success, build out an object and render
      // the page like so:
      res.render('some.template', {data: some_data});
  });
  </code></pre></li>
  </ol>
  
  <p>I think this is a decent example of what I'm trying to achieve, but what if we had even more async calls to handle? How can we exit the chain immediately? I've done a bit of searching and I know that I have a lot more to learn, but I'm not finding the ability to simply exit the chains immediately. </p>