Installations
npm install http-errors
Releases
Unable to fetch releases
Developer
jshttp
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 0.8
Typescript Support
No
Node Version
16.7.0
NPM Version
7.20.3
Statistics
1,505 Stars
295 Commits
115 Forks
27 Watching
3 Branches
36 Contributors
Updated on 18 Nov 2024
Bundle Size
6.14 kB
Minified
2.40 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
12,921,394,268
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
http-errors
Create HTTP errors for Express, Koa, Connect, etc. with ease.
Install
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install http-errors
Example
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})
API
This is the current API, currently extracted from Koa and subject to change.
Error Properties
expose
- can be used to signal ifmessage
should be sent to the client, defaulting tofalse
whenstatus
>= 500headers
- can be an object of header names to values to be sent to the client, defaulting toundefined
. 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, mirroringstatusCode
for general compatibilitystatusCode
- the status code of the error, defaulting to500
createError([status], [message], [properties])
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 object
createError([status], [error], [properties])
Extend 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 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
.
1var err = new createError.NotFound()
code
- the status code as a numbername
- the name of the error as a "bumpy case", i.e.NotFound
orInternalServerError
.
List of all constructors
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 |
License
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/jshttp/.github/SECURITY.md:1
- Warn: no linked content found
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/jshttp/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/jshttp/.github/SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:111: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/http-errors/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:174: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/http-errors/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:186: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/http-errors/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:134
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:150
- Info: 3 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 3 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
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
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: topLevel permissions set to 'read-all': .github/workflows/scorecard.yml:18
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Score
3.9
/10
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