# http-error-prototype

> A simple module to deal coherently with HTTP errors in Express

Latest version **1.0.0** (published 2019-08-06) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install http-error-prototype
pnpm add http-error-prototype
yarn add http-error-prototype
bun add http-error-prototype
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-08-06 |
| First published | 2019-08-06 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michele Tibaldi |
| Maintainers | uwburn |

## Links

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

## Recent versions

- 1.0.0 (latest) — 2019-08-06

## README

# HTTP error prototype

A simple module to deal coherently with HTTP errors in Express. Has conveniency methods for the most commons HTTP error codes. See `http-error-express` for the companion error handling middleware. 

### Usage

```javascript
var express = require('express');
var HttpError = require('http-error-prototype');

var router = express.Router();

// Shorthand method
router.get('/shorthand', function(req, res, next) {
	return next(HttpError.notFound("Some not found message", { someProp: "someVal" }));
});

// Constructor
router.get('/constructor', function(req, res, next) {
	return next(new HttpError(404, "Some not found message", { someProp: "someVal" }));
});

module.exports = router;
```

### API
- `new HttpError(status, message, data)`.
- ` HttpError.badRequest(status, message, data)`.
- ` HttpError.unauthorized(status, message, data)`.
- ` HttpError.forbidden(status, message, data)`.
- ` HttpError.notFound(status, message, data)`.
- ` HttpError.methodNotAllowed(status, message, data)`.
- ` HttpError.notAcceptable(status, message, data)`.
- ` HttpError.requestTimeout(status, message, data)`.
- ` HttpError.conflict(status, message, data)`.
 
Both `message` and `data` are optional.

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