# @mapbox/mapbox-error

> Error middleware for express apps

Latest version **5.0.0** (published 2025-06-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @mapbox/mapbox-error
pnpm add @mapbox/mapbox-error
yarn add @mapbox/mapbox-error
bun add @mapbox/mapbox-error
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2025-06-11 |
| First published | 2018-10-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 24.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mapbox |
| Maintainers | 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 |

## Links

- npm: https://www.npmjs.com/package/@mapbox/mapbox-error
- Repository: https://github.com/mapbox/mapbox-error
- Homepage: https://github.com/mapbox/mapbox-error#readme
- Issues: https://github.com/mapbox/mapbox-error/issues
- npm.io page: https://npm.io/package/@mapbox/mapbox-error

## Recent versions

- 5.0.0 (latest) — 2025-06-11
- 4.2.0-alpha.0 (dev) — 2025-06-11
- 4.1.0-alpha.0 — 2025-06-11
- 4.1.0-dev1 — 2025-02-21
- 4.0.0 — 2024-08-14
- 4.0.0-dev.3 — 2024-08-14
- 4.0.0-dev.2 — 2024-08-14
- 4.0.0-dev.1 — 2024-08-14
- 3.1.0 — 2022-06-30
- 3.0.3 — 2022-04-12
- 3.0.2 — 2021-12-03
- 3.1.0-dev3 — 2020-07-27
- 3.1.0-dev2 — 2020-07-24
- 4.0.0-dev2 — 2020-07-23
- 4.0.0-dev — 2020-07-23
- … 3 more at https://npm.io/package/@mapbox/mapbox-error/versions

## README

[![Run tests](https://github.com/mapbox/mapbox-error/actions/workflows/test.yml/badge.svg)](https://github.com/mapbox/mapbox-error/actions/workflows/test.yml)

# @mapbox/mapbox-error

Generic error middleware for express.js apps.

### usage

Install

```
npm i @mapbox/mapbox-error
```

Example application

```js
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

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

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

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

### develop

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

---
_Source: https://npm.io/package/@mapbox/mapbox-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
