Sails js beforeCreate next() callback custom response

95 views
Skip to first unread message

Devendra Verma

unread,
Oct 8, 2016, 1:01:25 AM10/8/16
to sails.js
I am using sails js for my web application. I have to change the default behaviour of beforeCreate. First look at the code:
beforeCreate: function(values, next) {

    //ParamsCheck is my service and 'check' is method which will validate the
    //parameters and if any invalid parameter then error will be thrown, otherwise 
    //no error will be thrown

    ParamsCheck.check(values)
   .then(() => {
     // All Params are valid and no error
     next();
   })
   .catch((err) => {
     //Some errors in params, and error is thrown
     next(err);
   });
}
So, the problem is if there is any error, then next method is automatically redirecting to serverError with error code 500, while I want to redirect it with my custom response(eg : badRequest , err code 400). How to achieve this? 
Reply all
Reply to author
Forward
0 new messages