Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adonisjs-bugsnag

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonisjs-bugsnag

BugSnag addon/plugin package for AdonisJS 4.0+ apps

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

adonis-bugsnag

An addon/plugin package to provide BugSnag error reporting services in AdonisJS 4.0+

NPM Version Build Status Coveralls

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')

/**
 * 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


    npm i


    npm run lint

    npm run test

Credits

Contributing

See the CONTRIBUTING.md file for info

Keywords

FAQs

Package last updated on 16 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc