title: sails.js/waterline validation error handlig
body: <p>I'm quite confused on how I should manage error validations from waterline, I need some clarification on good practices.
  Usually I have chains of promises like this:</p>
  
  <pre><code>  sails.models.user.findOne(...)
    .then(function(){
        //...
        //...
        return sails.models.user.update(...);
    })
    .then(....)
    .then(....)
    .catch(function(err){
  
    })
  </code></pre>
  
  <p>one problem that arises is when waterline returns a validation error. In this case, I usually need to know when the problem is generated by a wrong input by the client, or a bug in the code.</p>
  
  <p>What I eventually do is wrap the waterline promise in a promise which handle the validation error properly. So the final code would be:</p>
  
  <pre><code>  ...
    .then(function(){
        //...
        //...
        return new Promise(function(resolve,reject){
          sails.models.user.update(...)
          .then(resolve)
          .catch(function(err){
              //the error is a bug, return the error object inside the waterline WLError
              reject(err._e);
  
              //the error is caused by wrong input, return the waterline WLError
              reject(err);
          })
        })
    })
    .then(function(){
          //second example: we are sure that a validation error can't be caused by a wrong input
          return wrapPromise(sails.models.user.find());
    })
    .then(....)
    .catch(function(err){
        //WLError ---&gt; res.send(400);
        //Error object --&gt; res.send(500);
    })
  
  
    function wrapPromise(action){
        //return an error object on validation error
        return new Promise(function(resolve,reject){
            action
            .then(resolve)
            .catch(function(err){
                reject(err._e || err);
            })
        })
    }
  </code></pre>
  
  <p>am I doing things correctly? are there better methods to handle errors properly?
  thanks</p>