mycro-error
a mycro hook that provides an error
service with utility error handling methods.
Install
install
npm install --save mycro-error
add to hooks
// in config/hooks.jsmoduleexports = // .. 'services' 'mycro-error' // ..
Getting Started
Add a custom notifier. By default, the only notifier enabled is a logger
notifier
// hooks/bugsnag.jsvar bugsnag = ; module { let mycro = this; bugsnag; mycroserviceserror; ;}
Handle an error
let errorService = mycroserviceserror;// ..if err errorService;
Intercept an error
// default functionality; // prevent the callback from executing;
Add a custom error response handler
errorService { // inspect the error or serialize it res;}
Intercept a response handler
async;
Define your applications errors in a config file
// in config/errors.jsmoduleexports = badRequest: status: 400 title: 'Bad Request' query: status: 500 title: 'Database Query Error'
Convert errors into defined errors
Posts;
Or, better yet, wrap your callbacks
joi;
And, you can even call your notifiers with the raw error first
Posts;
Testing
run the test suite
npm test
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
Copyright (c) 2016 Chris Ludden. Licensed under the MIT License