title: A way to prevent highly nested code in Sequelize for error handling?
body: <p>I have a form and when something doesn't go right after submission, I want to be able to give the user specific error messages. I am using Sequelize as my ORM, and the promises returned are getting a bit messy with all the nested code. </p>
  
  <p>For instance, if we have two models to update: <code>User</code> and <code>Photo</code>:</p>
  
  <pre><code>models.User.find({where: {name: 'bob' }}).then(function(user) {
      if(user) {
          user.updateAttributes({email: email}).then(function(user) {
              models.Photo.find({where: { hash: hash}}).then(function(photo) {
                 if(photo)
                     res.json({"message":"updated"});
                 else
                     res.status(404).json({"error": "Could not find Photo"});
              }).catch(err) {
                 res.status(500).json({"error": err});
              });
          }).catch(function(err) {
              res.status(500).json({"error": err});
          });
      } else {
          res.status(404).json({"error": "Could not find user"});
      } 
  }).catch(function(err) {
      res.status(500).json({"error": err});
  });
  </code></pre>
  
  <p>And if I have 10 fields in the form to update, all the nested code can become overbearing. </p>
  
  <p>What recommendations can be given if I wish to have specific error descriptions, but also more readable code? Would it be possible to capture all the 404 and 500 errors in one code block instead of breaking them up like I have?</p>