@mapbox/mapbox-error
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

Run tests

@mapbox/mapbox-error

Generic error middleware for express.js apps.

usage

Install

npm i @mapbox/mapbox-error

Example application

import { showError, notFound, ErrorHTTP } from '@mapbox/mapbox-error';
import { express } from 'express';

const server = express();

// use ErrorHTTP to associate a status code and message to an Error object
server.get('/error', (req, res, next) => {
  return next(new ErrorHTTP('Error for the sake of errors', 400));
});

// put these after all routes have been loaded
server.use(showError());
server.use(notFound());

You can create and re-use error classes

import { customErrorHTTP } from '@mapbox/mapbox-error';

const InvalidToken = customErrorHTTP('InvalidToken', 401);

// within an express middleware...
next(new InvalidToken());

develop

npm ci          # install deps
npm run build   # build project
npm test        # run tests
npm run lint    # lint

Readme

Keywords

none

Package Sidebar

Install

npm i @mapbox/mapbox-error

Weekly Downloads

1,691

Version

4.0.0

License

ISC

Unpacked Size

23.6 kB

Total Files

14

Last publish

Collaborators

  • mapbox-npm-01
  • mapbox-npm-02
  • mapbox-npm-07
  • mapbox-npm-03
  • mapbox-npm-04
  • mapbox-npm-09
  • mapbox-npm-05
  • mapbox-npm-06
  • mapbox-npm-08
  • mapbox-npm-advanced-actions
  • mapbox-npm-ci
  • mapbox-npm
  • mapbox-admin
  • mapbox-machine-user
  • mbx-npm-ci-staging
  • mbx-npm-ci-production
  • mbx-npm-01-production
  • mbx-npm-02-production
  • mbx-npm-03-production
  • mbx-npm-04-production
  • mbx-npm-05-production
  • mbx-npm-06-production
  • mbx-npm-07-production
  • mbx-npm-08-production
  • mbx-npm-09-production
  • mbx-npm-02-staging
  • mbx-npm-advanced-actions-staging
  • mbx-npm-advanced-actions-production