# @financial-times/ip-custom-errors

> Generates custom Http errors

Latest version **1.0.1** (published 2018-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @financial-times/ip-custom-errors
pnpm add @financial-times/ip-custom-errors
yarn add @financial-times/ip-custom-errors
bun add @financial-times/ip-custom-errors
```

## 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.1 |
| Published | 2018-06-01 |
| First published | 2018-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Internal Products |
| Maintainers | aendrew, bobhaslett, callumlocke, ft-internal-products, i-like-robots, jakedchampion, joannaskao, mattandrews, quarterto, robinmarr-ft, rowanmanning, sdbernard, the-ft, zhenyulin |

## Links

- npm: https://www.npmjs.com/package/@financial-times/ip-custom-errors
- Repository: https://github.com/financial-times/ip-custom-errors
- Homepage: https://github.com/Financial-Times/ip-custom-errors#readme
- Issues: https://github.com/Financial-Times/ip-custom-errors/issues
- npm.io page: https://npm.io/package/@financial-times/ip-custom-errors

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## Recent versions

- 1.0.1 (latest) — 2018-06-01
- 1.0.0 — 2018-06-01
- 0.0.1 — 2018-05-22

## README

# ip-custom-errors

[![npm version](https://badge.fury.io/js/%40financial-times%2Fip-custom-errors.svg)](https://badge.fury.io/js/%40financial-times%2Fip-custom-errors)
[![CircleCI](https://circleci.com/gh/Financial-Times/ip-custom-errors.svg?style=svg&circle-token=3dd30815e8d7254babcade4bf0bf33c178925c79)](https://circleci.com/gh/Financial-Times/ip-custom-errors)

A module that generates custom HTTP errors

## setup

Install via npm:

```sh
  npm i -S @financial-times/ip-custom-errors
```

## Usage

The module exposes three methods to generate the custom HTTP errors. You can use the one that fits your needs as follows:

### Using the custom HttpError constructor to create a custom error message, for example: 
```javascript
const { HTTPError } = require('@financial-times/ip-custom-errors');
try {
  ...
  throw new HTTPError(401,'Unauthorized','You are not allowed to access this resource')
} catch (err) {
  console.error(err)
}

```
### Using the custom HTTPStatusError method with status code and custom message, for example:

```javascript
const { HTTPStatusErrors } = require('@financial-times/ip-custom-errors');
try {
  ...
  throw HTTPStatusErrors['400']('You are not allowed to access this resource')
} catch (err) {
  console.error(err)
}
```

### Using the name of the custom error by name
```javascript
const { NotFound } = require('@financial-times/ip-custom-errors');
try {
  ...
  throw NotFound("The resource you requested can't be found");
} catch (err) {
  console.error(err)
}
```
#### List of error names to use 
 
||||
|:-----------------------------|:--------------------------|:-----------------------------|
| BadRequest                   | UnsupportedMediaType      | NotImplemented               |       
| Unauthorized                 | RangeNotSatisfiable       | BadGateway                   |          
| PaymentRequired              | Expectation               | HttpVersionNotSupported      |  
| Forbidden                    | MisdirectedRequest        | VariantAlsoNegotiates        |   
| NotFound                     | UnprocessableEntity       | InsufficientStorage          |  
| MethodNotAllowed             | Locked                    | LoopDetected                 |  
| NotAcceptable                | UnorderedCollection       | NotExtended|                 |
| ProxyAuthenticationRequired  | UpgradeRequired           | NetworkAuthenticationRequired|        
| RequestTimeout               | PreconditionRequired      | ServiceUnavailable           |                           
| Conflict                     | TooManyRequests           | GatewayTimeout               |
| Gone                         | UnavailableForLegalReasons| BandwidthLimitExceeded       |
| LengthRequired               | InternalServerError       |
| PreconditionFailed           | ImATeapot                 |
| PayloadTooLarge              | FailedDependency          |
| UriTooLong                   | RequestHeaderFieldsTooLarge |




























## Licence

MIT

---
_Source: https://npm.io/package/@financial-times/ip-custom-errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
