adonis-bugsnag
An addon/plugin package to provide BugSnag error reporting services in AdonisJS 4.0+
Getting Started
Install from the NPM Registry using the Adonis command so that all post-install instructions are run
$ adonis install adonisjs-bugsnag
$ adonis make:ehandler
Format the Exceptions/Handler.js file for an AdonisJS application to look like this
const BaseExceptionHandler = use('BaseExceptionHandler')
const bugsnag = use('BugSnag')
class ExceptionHandler extends BaseExceptionHandler {
async handle(error, { request, response }) {
if (error.code === 'EBADCSRFTOKEN') {
response.forbidden('Cannot process request because this page expired!')
return
}
response.status(error.status).send(error.message)
}
async report(error, { request }) {
let metaData = {
headers: request.headers(),
format: request.format(),
body: request.hasBody() ? request.post() : {},
query: request.get(),
method: request.method().toLowerCase()
};
metaData[(metaData.method == "get" ? "querystring" : "entity_body")] = request.all()
await bugsnag.notify(error, request, metaData)
}
}
module.exports = ExceptionHandler
License
MIT
Running Tests
npm i
npm run lint
npm run test
Credits
Contributing
See the CONTRIBUTING.md file for info