opusdev/vector-similarity-api
1
1# http-errors2 3[![NPM Version][npm-version-image]][npm-url]4[![NPM Downloads][npm-downloads-image]][node-url]5[![Node.js Version][node-image]][node-url]6[![Build Status][ci-image]][ci-url]7[![Test Coverage][coveralls-image]][coveralls-url]8 9Create HTTP errors for Express, Koa, Connect, etc. with ease.10 11## Install12 13This is a [Node.js](https://nodejs.org/en/) module available through the14[npm registry](https://www.npmjs.com/). Installation is done using the15[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):16 17```console18$ npm install http-errors19```20 21## Example22 23```js24var createError = require('http-errors')25var express = require('express')26var app = express()27 28app.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## API35 36This is the current API, currently extracted from Koa and subject to change.37 38### Error Properties39 40- `expose` - can be used to signal if `message` should be sent to the client,41 defaulting to `false` when `status` >= 50042- `headers` - can be an object of header names to values to be sent to the43 client, defaulting to `undefined`. When defined, the key names should all44 be lower-cased45- `message` - the traditional error message, which should be kept short and all46 single line47- `status` - the status code of the error, mirroring `statusCode` for general48 compatibility49- `statusCode` - the status code of the error, defaulting to `500`50 51### createError([status], [message], [properties])52 53Create a new error object with the given message `msg`.54The error object inherits from `createError.HttpError`.55 56```js57var err = createError(404, 'This video does not exist!')58```59 60- `status: 500` - the status code as a number61- `message` - the message of the error, defaulting to node's text for that status code.62- `properties` - custom properties to attach to the object63 64### createError([status], [error], [properties])65 66Extend the given `error` object with `createError.HttpError`67properties. This will not alter the inheritance of the given68`error` object, and the modified `error` object is the69return value.70 71<!-- eslint-disable no-redeclare -->72 73```js74fs.readFile('foo.txt', function (err, buf) {75 if (err) {76 if (err.code === 'ENOENT') {77 var httpError = createError(404, err, { expose: false })78 } else {79 var httpError = createError(500, err)80 }81 }82})83```84 85- `status` - the status code as a number86- `error` - the error object to extend87- `properties` - custom properties to attach to the object88 89### createError.isHttpError(val)90 91Determine if the provided `val` is an `HttpError`. This will return `true`92if the error inherits from the `HttpError` constructor of this module or93matches the "duck type" for an error this module creates. All outputs from94the `createError` factory will return `true` for this function, including95if an non-`HttpError` was passed into the factory.96 97### new createError\[code || name\](\[msg]\))98 99Create a new error object with the given message `msg`.100The error object inherits from `createError.HttpError`.101 102```js103var err = new createError.NotFound()104```105 106- `code` - the status code as a number107- `name` - the name of the error as a "bumpy case", i.e. `NotFound` or `InternalServerError`.108 109#### List of all constructors110 111|Status Code|Constructor Name |112|-----------|-----------------------------|113|400 |BadRequest |114|401 |Unauthorized |115|402 |PaymentRequired |116|403 |Forbidden |117|404 |NotFound |118|405 |MethodNotAllowed |119|406 |NotAcceptable |120|407 |ProxyAuthenticationRequired |121|408 |RequestTimeout |122|409 |Conflict |123|410 |Gone |124|411 |LengthRequired |125|412 |PreconditionFailed |126|413 |PayloadTooLarge |127|414 |URITooLong |128|415 |UnsupportedMediaType |129|416 |RangeNotSatisfiable |130|417 |ExpectationFailed |131|418 |ImATeapot |132|421 |MisdirectedRequest |133|422 |UnprocessableEntity |134|423 |Locked |135|424 |FailedDependency |136|425 |TooEarly |137|426 |UpgradeRequired |138|428 |PreconditionRequired |139|429 |TooManyRequests |140|431 |RequestHeaderFieldsTooLarge |141|451 |UnavailableForLegalReasons |142|500 |InternalServerError |143|501 |NotImplemented |144|502 |BadGateway |145|503 |ServiceUnavailable |146|504 |GatewayTimeout |147|505 |HTTPVersionNotSupported |148|506 |VariantAlsoNegotiates |149|507 |InsufficientStorage |150|508 |LoopDetected |151|509 |BandwidthLimitExceeded |152|510 |NotExtended |153|511 |NetworkAuthenticationRequired|154 155## License156 157[MIT](LICENSE)158 159[ci-image]: https://badgen.net/github/checks/jshttp/http-errors/master?label=ci160[ci-url]: https://github.com/jshttp/http-errors/actions?query=workflow%3Aci161[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/http-errors/master162[coveralls-url]: https://coveralls.io/r/jshttp/http-errors?branch=master163[node-image]: https://badgen.net/npm/node/http-errors164[node-url]: https://nodejs.org/en/download165[npm-downloads-image]: https://badgen.net/npm/dm/http-errors166[npm-url]: https://npmjs.org/package/http-errors167[npm-version-image]: https://badgen.net/npm/v/http-errors168[travis-image]: https://badgen.net/travis/jshttp/http-errors/master169[travis-url]: https://travis-ci.org/jshttp/http-errors170 