Gathering detailed insights and metrics for http-errors
Gathering detailed insights and metrics for http-errors
Gathering detailed insights and metrics for http-errors
Gathering detailed insights and metrics for http-errors
npm install http-errors
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
1,505 Stars
295 Commits
115 Forks
27 Watching
3 Branches
36 Contributors
Updated on 18 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3%
11,680,280
Compared to previous day
Last week
2.7%
62,714,566
Compared to previous week
Last month
12%
258,485,198
Compared to previous month
Last year
0.7%
2,738,003,595
Compared to previous year
Create HTTP errors for Express, Koa, Connect, etc. with ease.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install http-errors
1var createError = require('http-errors') 2var express = require('express') 3var app = express() 4 5app.use(function (req, res, next) { 6 if (!req.user) return next(createError(401, 'Please login to view this page.')) 7 next() 8})
This is the current API, currently extracted from Koa and subject to change.
expose
- can be used to signal if message
should be sent to the client,
defaulting to false
when status
>= 500headers
- can be an object of header names to values to be sent to the
client, defaulting to undefined
. When defined, the key names should all
be lower-casedmessage
- the traditional error message, which should be kept short and all
single linestatus
- the status code of the error, mirroring statusCode
for general
compatibilitystatusCode
- the status code of the error, defaulting to 500
Create a new error object with the given message msg
.
The error object inherits from createError.HttpError
.
1var err = createError(404, 'This video does not exist!')
status: 500
- the status code as a numbermessage
- the message of the error, defaulting to node's text for that status code.properties
- custom properties to attach to the objectExtend the given error
object with createError.HttpError
properties. This will not alter the inheritance of the given
error
object, and the modified error
object is the
return value.
1fs.readFile('foo.txt', function (err, buf) {
2 if (err) {
3 if (err.code === 'ENOENT') {
4 var httpError = createError(404, err, { expose: false })
5 } else {
6 var httpError = createError(500, err)
7 }
8 }
9})
status
- the status code as a numbererror
- the error object to extendproperties
- custom properties to attach to the objectDetermine 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.
Create a new error object with the given message msg
.
The error object inherits from createError.HttpError
.
1var err = new createError.NotFound()
code
- the status code as a numbername
- the name of the error as a "bumpy case", i.e. NotFound
or InternalServerError
.Status Code | Constructor Name |
---|---|
400 | BadRequest |
401 | Unauthorized |
402 | PaymentRequired |
403 | Forbidden |
404 | NotFound |
405 | MethodNotAllowed |
406 | NotAcceptable |
407 | ProxyAuthenticationRequired |
408 | RequestTimeout |
409 | Conflict |
410 | Gone |
411 | LengthRequired |
412 | PreconditionFailed |
413 | PayloadTooLarge |
414 | URITooLong |
415 | UnsupportedMediaType |
416 | RangeNotSatisfiable |
417 | ExpectationFailed |
418 | ImATeapot |
421 | MisdirectedRequest |
422 | UnprocessableEntity |
423 | Locked |
424 | FailedDependency |
425 | TooEarly |
426 | UpgradeRequired |
428 | PreconditionRequired |
429 | TooManyRequests |
431 | RequestHeaderFieldsTooLarge |
451 | UnavailableForLegalReasons |
500 | InternalServerError |
501 | NotImplemented |
502 | BadGateway |
503 | ServiceUnavailable |
504 | GatewayTimeout |
505 | HTTPVersionNotSupported |
506 | VariantAlsoNegotiates |
507 | InsufficientStorage |
508 | LoopDetected |
509 | BandwidthLimitExceeded |
510 | NotExtended |
511 | NetworkAuthenticationRequired |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 3/21 approved changesets -- score normalized to 1
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More