navbar is-active
[josuexyz/.git] / node_modules / http-errors / README.md
1 # http-errors
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
8
9 Create HTTP errors for Express, Koa, Connect, etc. with ease.
10
11 ## Install
12
13 This is a [Node.js](https://nodejs.org/en/) module available through the
14 [npm registry](https://www.npmjs.com/). Installation is done using the
15 [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
16
17 ```bash
18 $ npm install http-errors
19 ```
20
21 ## Example
22
23 ```js
24 var createError = require('http-errors')
25 var express = require('express')
26 var app = express()
27
28 app.use(function (req, res, next) {
29   if (!req.user) return next(createError(401, 'Please login to view this page.'))
30   next()
31 })
32 ```
33
34 ## API
35
36 This is the current API, currently extracted from Koa and subject to change.
37
38 All errors inherit from JavaScript `Error` and the exported `createError.HttpError`.
39
40 ### Error Properties
41
42 - `expose` - can be used to signal if `message` should be sent to the client,
43   defaulting to `false` when `status` >= 500
44 - `headers` - can be an object of header names to values to be sent to the
45   client, defaulting to `undefined`. When defined, the key names should all
46   be lower-cased
47 - `message` - the traditional error message, which should be kept short and all
48   single line
49 - `status` - the status code of the error, mirroring `statusCode` for general
50   compatibility
51 - `statusCode` - the status code of the error, defaulting to `500`
52
53 ### createError([status], [message], [properties])
54
55 <!-- eslint-disable no-undef, no-unused-vars -->
56
57 ```js
58 var err = createError(404, 'This video does not exist!')
59 ```
60
61 - `status: 500` - the status code as a number
62 - `message` - the message of the error, defaulting to node's text for that status code.
63 - `properties` - custom properties to attach to the object
64
65 ### new createError\[code || name\](\[msg]\))
66
67 <!-- eslint-disable no-undef, no-unused-vars -->
68
69 ```js
70 var err = new createError.NotFound()
71 ```
72
73 - `code` - the status code as a number
74 - `name` - the name of the error as a "bumpy case", i.e. `NotFound` or `InternalServerError`.
75
76 #### List of all constructors
77
78 |Status Code|Constructor Name             |
79 |-----------|-----------------------------|
80 |400        |BadRequest                   |
81 |401        |Unauthorized                 |
82 |402        |PaymentRequired              |
83 |403        |Forbidden                    |
84 |404        |NotFound                     |
85 |405        |MethodNotAllowed             |
86 |406        |NotAcceptable                |
87 |407        |ProxyAuthenticationRequired  |
88 |408        |RequestTimeout               |
89 |409        |Conflict                     |
90 |410        |Gone                         |
91 |411        |LengthRequired               |
92 |412        |PreconditionFailed           |
93 |413        |PayloadTooLarge              |
94 |414        |URITooLong                   |
95 |415        |UnsupportedMediaType         |
96 |416        |RangeNotSatisfiable          |
97 |417        |ExpectationFailed            |
98 |418        |ImATeapot                    |
99 |421        |MisdirectedRequest           |
100 |422        |UnprocessableEntity          |
101 |423        |Locked                       |
102 |424        |FailedDependency             |
103 |425        |UnorderedCollection          |
104 |426        |UpgradeRequired              |
105 |428        |PreconditionRequired         |
106 |429        |TooManyRequests              |
107 |431        |RequestHeaderFieldsTooLarge  |
108 |451        |UnavailableForLegalReasons   |
109 |500        |InternalServerError          |
110 |501        |NotImplemented               |
111 |502        |BadGateway                   |
112 |503        |ServiceUnavailable           |
113 |504        |GatewayTimeout               |
114 |505        |HTTPVersionNotSupported      |
115 |506        |VariantAlsoNegotiates        |
116 |507        |InsufficientStorage          |
117 |508        |LoopDetected                 |
118 |509        |BandwidthLimitExceeded       |
119 |510        |NotExtended                  |
120 |511        |NetworkAuthenticationRequired|
121
122 ## License
123
124 [MIT](LICENSE)
125
126 [npm-image]: https://img.shields.io/npm/v/http-errors.svg
127 [npm-url]: https://npmjs.org/package/http-errors
128 [node-version-image]: https://img.shields.io/node/v/http-errors.svg
129 [node-version-url]: https://nodejs.org/en/download/
130 [travis-image]: https://img.shields.io/travis/jshttp/http-errors.svg
131 [travis-url]: https://travis-ci.org/jshttp/http-errors
132 [coveralls-image]: https://img.shields.io/coveralls/jshttp/http-errors.svg
133 [coveralls-url]: https://coveralls.io/r/jshttp/http-errors
134 [downloads-image]: https://img.shields.io/npm/dm/http-errors.svg
135 [downloads-url]: https://npmjs.org/package/http-errors