# http-json-error-handler

> Express error handlers for JSON APIs in development and production environments

Latest version **1.1.0** (published 2019-09-04) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install http-json-error-handler
pnpm add http-json-error-handler
yarn add http-json-error-handler
bun add http-json-error-handler
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-09-04 |
| First published | 2019-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Leonardo Furnielis |
| Maintainers | leofur1 |
| Keywords | api, express, error, handler, http, json |

## Links

- npm: https://www.npmjs.com/package/http-json-error-handler
- Repository: https://github.com/leofur1/http-json-error-handler
- Homepage: https://github.com/leofur1/http-json-error-handler#readme
- Issues: https://github.com/leofur1/http-json-error-handler/issues
- npm.io page: https://npm.io/package/http-json-error-handler

## Dependencies (1)

- [log4js](https://npm.io/package/log4js.md) 5.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-09-04
- 1.0.6 — 2019-09-02
- 1.0.5 — 2019-08-29
- 1.0.4 — 2019-08-29
- 1.0.3 — 2019-08-27
- 1.0.2 — 2019-07-30
- 1.0.1 — 2019-07-30
- 0.19.3 — 2019-07-24
- 0.19.2 — 2019-07-24
- 0.19.1 — 2019-07-24
- 0.19.0 — 2019-07-24
- 0.18.6 — 2019-07-24
- 0.18.5 — 2019-07-24
- 0.18.4 — 2019-07-24
- 0.18.3 — 2019-07-24
- … 1 more at https://npm.io/package/http-json-error-handler/versions

## README

# http-json-error-handler

![npm](https://img.shields.io/npm/v/http-json-error-handler)
[![Build Status](https://travis-ci.org/lfurnielis/http-json-error-handler.svg?branch=master)](https://travis-ci.org/lfurnielis/http-json-error-handler)
![GitHub](https://img.shields.io/github/license/lfurnielis/http-json-error-handler.svg)
![npm](https://img.shields.io/npm/dm/http-json-error-handler.svg)
[![Coverage Status](https://coveralls.io/repos/github/lfurnielis/http-json-error-handler/badge.svg?branch=master)](https://coveralls.io/github/lfurnielis/http-json-error-handler?branch=master)

## Installation

You can download `http-json-error-handler` from NPM

```bash

$ npm install http-json-error-handler --save

```

then in your project require http-json-error-handler

```js
const errorHandler = require('http-json-error-handler');
```

or GitHub

```bash

$ git clone https://github.com/lfurnielis/http-json-error-handler.git

```

## Guide

```js
const errorHandler =  require('http-json-error-handler');
const express = require('express');

const app = express();

// Your defined middlewares
...
...

// Your defined routes
app.get('/foo', (req, res, next) => {
    const error = new Error('Missing field(s): foo');
    error.status = 400;
    error.code = 10401;
    next(error);
});

// HTTP error handler
app.use(errorHandler({
	stderr: true // Default: false
}));
```

## Options

```js

{
  stderr: false // Log errors using console.error(), Default: false
  stackerr: false // Log error.stack using console.debug() only for statusCode >= 500, Default: false
}

```

### Definition of a "Error"

The error could contain the following fields:

| Error Key          | Purpose                                                                          |
| ------------------ | -------------------------------------------------------------------------------- |
| [message] | Error details.                                                                   |
| [status]  | HTTP status code for response. Default: 500 (Internal Server Error). |
| [code]    | Error code. Default: same as "status".                                  |

### HTTP JSON Error Example

```json
{
  "error": {
    "code": 10401,
    "message": "BAD REQUEST",
    "details": "Missing field(s): foo"
  }
}
```

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