Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

@expresso/errors

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@expresso/errors

@expresso express error handling suite

latest
Source
npmnpm
Version
1.3.3
Version published
Maintainers
2
Created
Source

Errors

Error middleware for expresso

Summary

  • Errors

How this works

The error middleware will receive all errors from @expresso/app (and every other error thrown inside any routes) and it is going to sanitize it to a default response pattern with message, code and stack informations. It'll also catch any unknown error messages and parse them as HTTP 500 errors.

Basic usage

Install it:

$ npm i @expresso/errors

Import and use it:

import route from './route'
import expresso, { IExpressoConfigOptions } from '@expresso/app'
import server from '@expresso/server'
import errors from '@expresso/errors'

interface IAppConfig extends IAuthConfig, IExpressoConfigOptions {}

const appFactory = expresso((app, config: IAppConfig, environment) => {

    app.get('/', route)

    app.use(errors(environment))
})

const options = {
  name: 'myApp',
  jwt: {
    algorithms: ['HS256'],
    audience: 'your-audience',
    issuer: 'your-issuer',
    secret: 'shhhhh'
  }
}

server.start(appFactory, options)

The error middleware receives a string declaring the current environment for your application. If this environment is different from production, then all the error stack will also be displayed.

Adding additional data

If you'd like to include more data in the error, pass on a boom error with { additionalData: yourData } as second parameter.

Example:

if (err instanceof ExternalAPIError) return next(boom.serverUnavailable(err.message, { additionalProperties: err.data }))

This will render the added data to the response

Keywords

express

FAQs

Package last updated on 24 Nov 2020

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