# @map-colonies/error-express-handler

> Express error handler for the MapColonies project

Latest version **4.0.0** (published 2026-01-19) · 0 weekly downloads

## Install

```sh
npm install @map-colonies/error-express-handler
pnpm add @map-colonies/error-express-handler
yarn add @map-colonies/error-express-handler
bun add @map-colonies/error-express-handler
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-01-19 |
| First published | 2020-12-31 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24 |
| Dependencies | 1 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | mapcolonies, syncush, asaf.masa, schnitz, konchashlomicl, shimoncohen, alebinson, netanelc, mapcolonies.devops, konchashlomi, ronenk |

## Links

- npm: https://www.npmjs.com/package/@map-colonies/error-express-handler
- Repository: https://github.com/MapColonies/infra-packages
- Homepage: https://github.com/MapColonies/infra-packages#readme
- Issues: https://github.com/MapColonies/infra-packages/issues
- npm.io page: https://npm.io/package/@map-colonies/error-express-handler

## Dependencies (1)

- [http-status-codes](https://npm.io/package/http-status-codes.md) ^2.3.0

## Recent versions

- 4.0.0 (latest) — 2026-01-19
- 3.0.0 — 2025-01-23
- 2.1.0 — 2021-10-13
- 2.0.0 — 2021-04-25
- 1.2.0 — 2021-01-20
- 1.1.0 — 2021-01-17
- 1.0.2 — 2021-01-05
- 1.0.1 — 2020-12-31
- 1.0.0 — 2020-12-31

## README

# error-express-handler

This package exports a middleware for express that handles Error and HttpError(custom package type).
## Install
```sh
npm install --save @map-colonies/error-express-handler
```

## API documentation
Check the autogenerated documentation [here](https://mapcolonies.github.io/infra-packages/modules/_map-colonies_error-express-handler.html).

## Usage
Add the handler as the last middleware, so any error forwarded by the controllers will be handled.
If the value of `NODE_ENV` is production the error message will be redacted and a generic one will be sent instead.
In development, in addition to the error message, the stack trace of the error will be included in the response.

```ts
import express from 'express';
import { getErrorHandlerMiddleware } from '@map-colonies/error-express-handler';

process.env.NODE_ENV = 'development';

const app = express();

app.use('/meow', fn);

app.use(getErrorHandlerMiddleware());

app.listen(8080, function() {
    console.log('server is up');
});
```

## Flow
```mermaid
flowchart TD
    A@{ label: "NODE_ENV='production'" } -- true --> B["error implements HttpError"]
    A -- false --> C["error implements HttpError"]
    B -- true --> D["Status code: err.StatusCode<br>body: {ﬂ°°34¶ßmessageﬂ°°34¶ß:ﬂ°°34¶ßerr.messageﬂ°°34¶ß}"]
    B -- false --> E["Status code: 500<br>body: {ﬂ°°34¶ßmessageﬂ°°34¶ß:ﬂ°°34¶ßInternal Server Errorﬂ°°34¶ß}"]
    C -- true --> F["Status code: err.StatusCode<br>body: {ﬂ°°34¶ßmessageﬂ°°34¶ß:ﬂ°°34¶ßerr.messageﬂ°°34¶ß}"]
    C -- false --> G["Status code: 500<br>body: {ﬂ°°34¶ßmessageﬂ°°34¶ß:ﬂ°°34¶ßInternal Server Errorﬂ°°34¶ß, ﬂ°°34stacktraceﬂ°°34:err.stack }"]

```

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