sails-hook-exception-handling
Capture all the errors that are thrown from the middlewares without adding try/catch in all of them.
Installation
$ npm install --save sails-hook-exception-handling
Sails v1.0 >= required, responses hook must be enabled.
Usage
await User // throws {code: E_UNIQUE} error
await User // throws {name: UsageError} error
This hooks will manage al the Waterline errors, sending to the user the error with the pertinent status. More info about Waterline errors.
{ throw 'notFound'; // sends res.notFound() } { throw 'badRequest'; // sends res.badRequest() } { throw 'forbidden'; // sends res.forbidden() }
All the unnexpected errors will be handled as status 500, with res.serverError(err) default method.
Test
// mocha required: npm i -g mocha npm test