https://github.com/stitchng/adonis-bugsnag
An addon/plugin package to provide BugSnag error reporting services in AdonisJS 4.0+
https://github.com/stitchng/adonis-bugsnag
adonis-framework adonisjs adonisjs-addon bugsnag-js error error-reporting reporter
Last synced: 8 months ago
JSON representation
An addon/plugin package to provide BugSnag error reporting services in AdonisJS 4.0+
- Host: GitHub
- URL: https://github.com/stitchng/adonis-bugsnag
- Owner: stitchng
- License: mit
- Created: 2018-12-10T10:55:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-16T00:46:13.000Z (over 4 years ago)
- Last Synced: 2025-08-13T21:58:18.252Z (10 months ago)
- Topics: adonis-framework, adonisjs, adonisjs-addon, bugsnag-js, error, error-reporting, reporter
- Language: JavaScript
- Homepage:
- Size: 96.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# adonis-bugsnag
An addon/plugin package to provide BugSnag error reporting services in AdonisJS 4.0+
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coveralls][coveralls-image]][coveralls-url]

## Getting Started
>Install from the NPM Registry using the Adonis command so that all post-install instructions are run
```bash
$ adonis install adonisjs-bugsnag
$ adonis make:ehandler
```
>Format the _Exceptions/Handler.js_ file for an AdonisJS application to look like this
```js
const BaseExceptionHandler = use('BaseExceptionHandler')
const bugsnag = use('BugSnag')
/**
* This class handles all exceptions thrown during
* the HTTP request lifecycle.
*
* @class ExceptionHandler
*/
class ExceptionHandler extends BaseExceptionHandler {
/**
* Handle exception thrown during the HTTP lifecycle
*
* @method handle
*
* @param {Object} error
* @param {Object} options.request
* @param {Object} options.response
*
* @return {void}
*/
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)
}
/**
* Report exception for logging or debugging.
*
* @method report
*
* @param {Object} error
* @param {Object} options.request
*
* @return {void}
*/
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
```bash
npm i
```
```bash
npm run lint
npm run test
```
## Credits
- [Ifeora Okechukwu ](https://twitter.com/isocroft)
- [Ahmad Abdul-Aziz ](https://twittwer.com/dev_amaz)
## Contributing
See the [CONTRIBUTING.md](https://github.com/stitchng/adonis-bugsnag/blob/master/CONTRIBUTING.md) file for info
[npm-image]: https://img.shields.io/npm/v/adonisjs-bugsnag.svg?style=flat-square
[npm-url]: https://npmjs.org/package/adonisjs-bugsnag
[travis-image]: https://img.shields.io/travis/stitchng/adonis-bugsnag/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/stitchng/adonis-bugsnag
[coveralls-image]: https://img.shields.io/coveralls/stitchng/adonis-bugsnag/develop.svg?style=flat-square
[coveralls-url]: https://coveralls.io/github/stitchng/adonis-bugsnag