| | |
| | | [![NPM Version][npm-version-image]][npm-url] |
| | | [![NPM Downloads][npm-downloads-image]][node-url] |
| | | [![Node.js Version][node-image]][node-url] |
| | | [![Build Status][travis-image]][travis-url] |
| | | [![Build Status][ci-image]][ci-url] |
| | | [![Test Coverage][coveralls-image]][coveralls-url] |
| | | |
| | | Create HTTP errors for Express, Koa, Connect, etc. with ease. |
| | |
| | | [npm registry](https://www.npmjs.com/). Installation is done using the |
| | | [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): |
| | | |
| | | ```bash |
| | | ```console |
| | | $ npm install http-errors |
| | | ``` |
| | | |
| | |
| | | Create a new error object with the given message `msg`. |
| | | The error object inherits from `createError.HttpError`. |
| | | |
| | | <!-- eslint-disable no-undef, no-unused-vars --> |
| | | |
| | | ```js |
| | | var err = createError(404, 'This video does not exist!') |
| | | ``` |
| | |
| | | `error` object, and the modified `error` object is the |
| | | return value. |
| | | |
| | | <!-- eslint-disable no-redeclare, no-undef, no-unused-vars --> |
| | | <!-- eslint-disable no-redeclare --> |
| | | |
| | | ```js |
| | | fs.readFile('foo.txt', function (err, buf) { |
| | |
| | | - `error` - the error object to extend |
| | | - `properties` - custom properties to attach to the object |
| | | |
| | | ### createError.isHttpError(val) |
| | | |
| | | Determine if the provided `val` is an `HttpError`. This will return `true` |
| | | if the error inherits from the `HttpError` constructor of this module or |
| | | matches the "duck type" for an error this module creates. All outputs from |
| | | the `createError` factory will return `true` for this function, including |
| | | if an non-`HttpError` was passed into the factory. |
| | | |
| | | ### new createError\[code || name\](\[msg]\)) |
| | | |
| | | Create a new error object with the given message `msg`. |
| | | The error object inherits from `createError.HttpError`. |
| | | |
| | | <!-- eslint-disable no-undef, no-unused-vars --> |
| | | |
| | | ```js |
| | | var err = new createError.NotFound() |
| | |
| | | |422 |UnprocessableEntity | |
| | | |423 |Locked | |
| | | |424 |FailedDependency | |
| | | |425 |UnorderedCollection | |
| | | |425 |TooEarly | |
| | | |426 |UpgradeRequired | |
| | | |428 |PreconditionRequired | |
| | | |429 |TooManyRequests | |
| | |
| | | |
| | | [MIT](LICENSE) |
| | | |
| | | [ci-image]: https://badgen.net/github/checks/jshttp/http-errors/master?label=ci |
| | | [ci-url]: https://github.com/jshttp/http-errors/actions?query=workflow%3Aci |
| | | [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/http-errors/master |
| | | [coveralls-url]: https://coveralls.io/r/jshttp/http-errors?branch=master |
| | | [node-image]: https://badgen.net/npm/node/http-errors |