🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

api-error-handler-revived

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-error-handler-revived

Express error handlers for JSON APIs

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

api-error-handler-revived

NPM NPM

Forked from api-error-handler since there were unmerged 2016 pull requests

An error handler for JSON APIs, meant to be used with http-errors-style errors.

Installation

npm i api-error-handler-revived

Example

var errorHandler = require('api-error-handler-revived');

var api = new express.Router();
api.get('/users/:userid', function (req, res, next) {

});

api.use(errorHandler());

app.use('/api', api);

API

.use(errorHandler([options]))

Options:

  • stack:
    • Description: Wether to show or not the stacktrace
    • Default: true
  • log
    • Description: Wether to console.error the error object
    • Default: true
  • suppressServer
    • Description: Wether to supress serverside (5xx) errors with a generic message
    • Default: true

Extra params

If you need to expose any other params, pass an extra property to the http-errors properties parameter:

createError(400, `There were errors validating sent data`, {extra: {errors: validationErrors}})

Errors

4xx errors are exposed to the client. Properties exposed are:

  • message
  • type
  • name
  • code
  • status
  • extra properties

5xx errors are, by default, not exposed to the client. Instead, they are given a generic message as well as the type.

Keywords

express

FAQs

Package last updated on 10 Oct 2017

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