title: Returning errors in nested then and promises ExpressJS/NodeJs
body: <p>I am having a bit of confusion on returning error from function calls.
  For example purpose, I am using sequelizeJS to illustrate the point.
  Normally:</p>
  
  <p><strong>First.Ctrl</strong></p>
  
  <pre><code>var second_ctrl = require( '../ctrl/second');
  testCode : function(req, res, next){
      return second_ctrl.getData()
            .then(function(resultData){
                  res.json(resultData);
            })
            .catch(function(error){
                  res.json(error)
            })
  }
  </code></pre>
  
  <p><strong>Second.Ctrl</strong></p>
  
  <pre><code>getData : function(){
      return models.Data.findAll()              
  }
  </code></pre>
  
  <p>Any error in the getData findAll would go to catch block of first_ctrl. But if I have to do some manipulations like:</p>
  
  <p><strong>Second.Ctrl - Manipulation</strong></p>
  
  <pre><code>getData : function(){
      return models.Data.findAll()
            .then(function(result){
                  if(result == null)
                     throw new Error ('No data found');
                  return  result;
            })
            .catch(function(error){
                  throw error;
                  //return error
            })
  }
  </code></pre>
  
  <p>I have tried using throw error, return error and removing the inner catch block but in both cases - the execution goes to then block in first_ctrl with resultData having received the error object. </p>
  
  <p>What is the best practice for this kind of situations as these nested call can go even deeper (first_ctrl -> second_ctrl -> third_ctrl)</p>
  
  <p>Let me know. Looking forward to your thoughts </p>