Gathering detailed insights and metrics for http-error-kit
Gathering detailed insights and metrics for http-error-kit
Gathering detailed insights and metrics for http-error-kit
Gathering detailed insights and metrics for http-error-kit
http-error-kit is a versatile and customizable error handling library for JavaScript and TypeScript applications. It provides a collection of HTTP error classes that can be tailored to fit various formatting needs, both globally and on a per-instance basis.
npm install http-error-kit
Typescript
Module System
Node Version
NPM Version
76.1
Supply Chain
99
Quality
77.9
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
416
Last Day
1
Last Week
2
Last Month
75
Last Year
416
MIT License
11 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Mar 23, 2025
Latest Version
1.1.0
Package Id
http-error-kit@1.1.0
Unpacked Size
335.37 kB
Size
25.59 kB
File Count
9
NPM Version
10.8.2
Node Version
20.18.0
Published on
Mar 08, 2025
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-33.3%
2
Compared to previous week
Last Month
33.9%
75
Compared to previous month
Last Year
0%
416
Compared to previous year
http-error-kit
is a versatile and customizable error handling library for JavaScript and TypeScript applications. It provides a collection of HTTP error classes that can be tailored to fit various formatting needs, both globally and on a per-instance basis.
NotFoundError
, BadRequestError
, InternalServerError
, etc.)1npm install http-error-kit
By default, importing error classes allows their format to be dynamically updated by changing the global formatter.
1const { BadRequestError } = require("http-error-kit"); 2// 3import { BadRequestError } from "http-error-kit"; 4 5console.log(new BadRequestError("Invalid request", { field: "email" })); 6/* BadRequestError { 7 * statusCode: 400, 8 * message: "Invalid request", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
After setting a global formatter, the same error class will follow the new structure defined by the formatter.
1const { BadRequestError, KitHttpErrorConfig } = require("http-error-kit"); 2// 3import { BadRequestError, KitHttpErrorConfig } from "http-error-kit"; 4 5const formatter = (statusCode, message, details, ...args) => ({ 6 code: statusCode, 7 msg: message, 8 extra: details, 9 traceId: args[0] || "default-trace-id", 10}); 11 12KitHttpErrorConfig.configureFormatter(formatter); 13 14console.log(new BadRequestError("Invalid request", { field: "email" })); 15/* BadRequestError { 16 * code: 400, 17 * msg: "Invalid request", 18 * extra: { 19 * field: "email" 20 * }, 21 * traceId: "default-trace-id" 22 * } 23 */
By default, if you import errors without any additional setup, you'll get the generic error implementations.
1const { BadRequestError } = require("http-error-kit"); 2// 3import { BadRequestError } from "http-error-kit"; 4 5console.log(new BadRequestError("Invalid request", { field: "email" })); 6/* BadRequestError { 7 * statusCode: 400, 8 * message: "Invalid request", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
This follows a simple structure without any additional formatting.
Note: If you prefer to use errors specifically with simple structure (extended by KitGeneralError
), you can explicitly import errors from:
1const { BadRequestError } = require("http-error-kit/generic");
You can set a global formatter to customize the error structure across your application.
To enable structured error responses, use KitHttpError
with global configuration:
1const { BadRequestError, KitHttpErrorConfig } = require("http-error-kit"); 2 3KitHttpErrorConfig.configureFormatter( 4 (statusCode, message, details, ...args) => ({ 5 code: statusCode, 6 msg: message, 7 extra: details, 8 traceId: args[0] || "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a", 9 }) 10); 11 12console.log( 13 new BadRequestError("Invalid request", { field: "email" }, "trace-123") 14); 15/* BadRequestError { 16 * code: 400, 17 * msg: "Invalid request", 18 * extra: { 19 * field: "email" 20 * }, 21 * traceId: "trace-123" 22 * } 23 */
A custom formatter allows you to modify the structure of error responses. The formatter function receives the following parameters:
Parameter | Description |
---|---|
statusCode | The HTTP status code (e.g., 400 for "Bad Request") |
message | The error message (e.g., "Invalid request" ) |
details | Additional error details (optional) |
...args | Extra arguments passed, such as a unique trace ID |
Feature | http-error-kit | http-error-kit/http | http-error-kit/generic |
---|---|---|---|
Error Type | Standardized errors (with global formatting) and can be overridden by instance-level formatters at the error instance level | Standardized errors (with global formatting) and can be overridden by instance-level formatters at the error instance level | Static format errors (no dynamic formatting) |
Import Path | import { BadRequestError } from "http-error-kit"; | import { BadRequestError } from "http-error-kit/http"; | import { BadRequestError } from "http-error-kit/generic"; |
Customization | Uses global formatter set via KitHttpErrorConfig.configureFormatter with the ability to change format with an instance-level formatter | Uses global formatter set via KitHttpErrorConfig.configureFormatter with the ability to change format with an instance-level formatter | Uses a fixed structure without formatting customization |
Formatter Usage | Global formatter applied to all errors dynamically but can be customized per instance and does not affect other instances | Global formatter applied to all errors dynamically but can be customized per instance and does not affect other instances | Always follows a predefined static structure |
Special Classes | KitGeneralError , KitHttpError , KitHttpErrorConfig | KitHttpError , KitHttpErrorConfig | KitGeneralError |
When to Use? | When you need a globally consistent error structure with the flexibility to override formatting per instance | When you need a globally consistent error structure with the flexibility to override formatting per instance | When you need lightweight, raw errors without customization |
Example Output | { code: 400, msg: "Invalid request", extra: { field: "email" }, traceId: "trace-123" } | { code: 400, msg: "Invalid request", extra: { field: "email" }, traceId: "trace-456" } | { status: 400, message: "Invalid request" } |
Best for | Large-scale applications needing standardized error responses with flexible formatting options | Applications needing flexible, instance-based error customization | Minimalist applications needing basic HTTP errors |
Important Note:
If a global formatter is set, all error classes imported from
http-error-kit
work likehttp-error-kit/http
.If no global formatter is set, all error classes imported from
http-error-kit
work likehttp-error-kit/generic
.
You can define a global formatter to standardize the structure of all error instances.
1const { KitHttpErrorConfig } = require("http-error-kit"); 2 3KitHttpErrorConfig.configureFormatter( 4 (statusCode, message, details, ...args) => ({ 5 code: statusCode, 6 msg: message, 7 extra: details, 8 traceId: args[0] || "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a", 9 }) 10);
This formatter will be applied to all error instances imported from the default path (http-error-kit
) and those from the http-error-kit/http
path, unless an instance-level formatter is set.
For specific cases, you can override the global formatter by setting an instance-level formatter.
1const { BadRequestError } = require("http-error-kit/http"); 2 3const instanceFormatter = (statusCode, message, details, ...args) => ({ 4 errorCode: statusCode, 5 errorMessage: message, 6 errorDetails: details, 7 requestId: args[0] || "instance-trace-id", 8}); 9 10console.log( 11 new BadRequestError( 12 "Invalid request", 13 { field: "email" }, 14 "trace-456" 15 ).setFormatter(instanceFormatter) 16); 17/* BadRequestError { 18 * errorCode: 400, 19 * errorMessage: "Invalid request", 20 * errorDetails: { 21 * field: "email" 22 * }, 23 * requestId: "trace-456" 24 * } 25 */
This will override the global formatter only for this instance
Creates a new instance of the KitGeneralError class with a status code of 400, Bad Request.
message
(string
): The error message. Defaults to the HTTP status code description for 400. (e.g., "Bad Request"
).details
(any
): Additional details about the error, if any.1const { BadRequestError } = require("http-error-kit"); 2 3console.log(new BadRequestError("Bad Request", { field: "email" })); 4/* BadRequestError { 5 * statusCode: 400, 6 * message: "Bad Request", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 401, Unauthorized.
message
(string
): The error message. Defaults to the HTTP status code description for 401. (e.g., "Unauthorized"
).details
(any
): Additional details about the error, if any.1const { UnauthorizedError } = require("http-error-kit"); 2 3console.log(new UnauthorizedError("Unauthorized", { field: "email" })); 4/* UnauthorizedError { 5 * statusCode: 401, 6 * message: "Unauthorized", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 402, Payment Required.
message
(string
): The error message. Defaults to the HTTP status code description for 402. (e.g., "Payment Required"
).details
(any
): Additional details about the error, if any.1const { PaymentRequiredError } = require("http-error-kit"); 2 3console.log(new PaymentRequiredError("Payment Required", { field: "email" })); 4/* PaymentRequiredError { 5 * statusCode: 402, 6 * message: "Payment Required", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 403, Forbidden.
message
(string
): The error message. Defaults to the HTTP status code description for 403. (e.g., "Forbidden"
).details
(any
): Additional details about the error, if any.1const { ForbiddenError } = require("http-error-kit"); 2 3console.log(new ForbiddenError("Forbidden", { field: "email" })); 4/* ForbiddenError { 5 * statusCode: 403, 6 * message: "Forbidden", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 404, Not Found.
message
(string
): The error message. Defaults to the HTTP status code description for 404. (e.g., "Not Found"
).details
(any
): Additional details about the error, if any.1const { NotFoundError } = require("http-error-kit"); 2 3console.log(new NotFoundError("Not Found", { field: "email" })); 4/* NotFoundError { 5 * statusCode: 404, 6 * message: "Not Found", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 405, Method Not Allowed.
message
(string
): The error message. Defaults to the HTTP status code description for 405. (e.g., "Method Not Allowed"
).details
(any
): Additional details about the error, if any.1const { MethodNotAllowedError } = require("http-error-kit"); 2 3console.log( 4 new MethodNotAllowedError("Method Not Allowed", { field: "email" }) 5); 6/* MethodNotAllowedError { 7 * statusCode: 405, 8 * message: "Method Not Allowed", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 406, Not Acceptable.
message
(string
): The error message. Defaults to the HTTP status code description for 406. (e.g., "Not Acceptable"
).details
(any
): Additional details about the error, if any.1const { NotAcceptableError } = require("http-error-kit"); 2 3console.log(new NotAcceptableError("Not Acceptable", { field: "email" })); 4/* NotAcceptableError { 5 * statusCode: 406, 6 * message: "Not Acceptable", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 407, Proxy Authentication Required.
message
(string
): The error message. Defaults to the HTTP status code description for 407. (e.g., "Proxy Authentication Required"
).details
(any
): Additional details about the error, if any.1const { ProxyAuthenticationRequiredError } = require("http-error-kit"); 2 3console.log( 4 new ProxyAuthenticationRequiredError("Proxy Authentication Required", { 5 field: "email", 6 }) 7); 8/* ProxyAuthenticationRequiredError { 9 * statusCode: 407, 10 * message: "Proxy Authentication Required", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 408, Request Timeout.
message
(string
): The error message. Defaults to the HTTP status code description for 408. (e.g., "Request Timeout"
).details
(any
): Additional details about the error, if any.1const { RequestTimeoutError } = require("http-error-kit"); 2 3console.log(new RequestTimeoutError("Request Timeout", { field: "email" })); 4/* RequestTimeoutError { 5 * statusCode: 408, 6 * message: "Request Timeout", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 409, Conflict.
message
(string
): The error message. Defaults to the HTTP status code description for 409. (e.g., "Conflict"
).details
(any
): Additional details about the error, if any.1const { ConflictError } = require("http-error-kit"); 2 3console.log(new ConflictError("Conflict", { field: "email" })); 4/* ConflictError { 5 * statusCode: 409, 6 * message: "Conflict", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 410, Gone.
message
(string
): The error message. Defaults to the HTTP status code description for 410. (e.g., "Gone"
).details
(any
): Additional details about the error, if any.1const { GoneError } = require("http-error-kit"); 2 3console.log(new GoneError("Gone", { field: "email" })); 4/* GoneError { 5 * statusCode: 410, 6 * message: "Gone", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 411, Length Required.
message
(string
): The error message. Defaults to the HTTP status code description for 411. (e.g., "Length Required"
).details
(any
): Additional details about the error, if any.1const { LengthRequiredError } = require("http-error-kit"); 2 3console.log(new LengthRequiredError("Length Required", { field: "email" })); 4/* LengthRequiredError { 5 * statusCode: 411, 6 * message: "Length Required", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 412, Precondition Failed.
message
(string
): The error message. Defaults to the HTTP status code description for 412. (e.g., "Precondition Failed"
).details
(any
): Additional details about the error, if any.1const { PreconditionFailedError } = require("http-error-kit"); 2 3console.log( 4 new PreconditionFailedError("Precondition Failed", { field: "email" }) 5); 6/* PreconditionFailedError { 7 * statusCode: 412, 8 * message: "Precondition Failed", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 413, Request Entity Too Large.
message
(string
): The error message. Defaults to the HTTP status code description for 413. (e.g., "Request Entity Too Large"
).details
(any
): Additional details about the error, if any.1const { RequestTooLongError } = require("http-error-kit"); 2 3console.log( 4 new RequestTooLongError("Request Entity Too Large", { field: "email" }) 5); 6/* RequestTooLongError { 7 * statusCode: 413, 8 * message: "Request Entity Too Large", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 414, Request-URI Too Long.
message
(string
): The error message. Defaults to the HTTP status code description for 414. (e.g., "Request-URI Too Long"
).details
(any
): Additional details about the error, if any.1const { RequestUriTooLongError } = require("http-error-kit"); 2 3console.log( 4 new RequestUriTooLongError("Request-URI Too Long", { field: "email" }) 5); 6/* RequestUriTooLongError { 7 * statusCode: 414, 8 * message: "Request-URI Too Long", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 415, Unsupported Media Type.
message
(string
): The error message. Defaults to the HTTP status code description for 415. (e.g., "Unsupported Media Type"
).details
(any
): Additional details about the error, if any.1const { UnsupportedMediaTypeError } = require("http-error-kit"); 2 3console.log( 4 new UnsupportedMediaTypeError("Unsupported Media Type", { field: "email" }) 5); 6/* UnsupportedMediaTypeError { 7 * statusCode: 415, 8 * message: "Unsupported Media Type", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 416, Requested Range Not Satisfiable.
message
(string
): The error message. Defaults to the HTTP status code description for 416. (e.g., "Requested Range Not Satisfiable"
).details
(any
): Additional details about the error, if any.1const { RequestedRangeNotSatisfiableError } = require("http-error-kit"); 2 3console.log( 4 new RequestedRangeNotSatisfiableError("Requested Range Not Satisfiable", { 5 field: "email", 6 }) 7); 8/* RequestedRangeNotSatisfiableError { 9 * statusCode: 416, 10 * message: "Requested Range Not Satisfiable", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 417, Expectation Failed.
message
(string
): The error message. Defaults to the HTTP status code description for 417. (e.g., "Expectation Failed"
).details
(any
): Additional details about the error, if any.1const { ExpectationFailedError } = require("http-error-kit"); 2 3console.log( 4 new ExpectationFailedError("Expectation Failed", { field: "email" }) 5); 6/* ExpectationFailedError { 7 * statusCode: 417, 8 * message: "Expectation Failed", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 418, I'm a teapot.
message
(string
): The error message. Defaults to the HTTP status code description for 418. (e.g., "I'm a teapot"
).details
(any
): Additional details about the error, if any.1const { ImATeapotError } = require("http-error-kit"); 2 3console.log(new ImATeapotError("I'm a teapot", { field: "email" })); 4/* ImATeapotError { 5 * statusCode: 418, 6 * message: "I'm a teapot", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 419, Insufficient Space on Resource.
message
(string
): The error message. Defaults to the HTTP status code description for 419. (e.g., "Insufficient Space on Resource"
).details
(any
): Additional details about the error, if any.1const { InsufficientSpaceOnResourceError } = require("http-error-kit"); 2 3console.log( 4 new InsufficientSpaceOnResourceError("Insufficient Space on Resource", { 5 field: "email", 6 }) 7); 8/* InsufficientSpaceOnResourceError { 9 * statusCode: 419, 10 * message: "Insufficient Space on Resource", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 420, Method Failure.
message
(string
): The error message. Defaults to the HTTP status code description for 420. (e.g., "Method Failure"
).details
(any
): Additional details about the error, if any.1const { MethodFailureError } = require("http-error-kit"); 2 3console.log(new MethodFailureError("Method Failure", { field: "email" })); 4/* MethodFailureError { 5 * statusCode: 420, 6 * message: "Method Failure", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 421, Misdirected Request.
message
(string
): The error message. Defaults to the HTTP status code description for 421. (e.g., "Misdirected Request"
).details
(any
): Additional details about the error, if any.1const { MisdirectedRequestError } = require("http-error-kit"); 2 3console.log( 4 new MisdirectedRequestError("Misdirected Request", { field: "email" }) 5); 6/* MisdirectedRequestError { 7 * statusCode: 421, 8 * message: "Misdirected Request", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 422, Unprocessable Entity.
message
(string
): The error message. Defaults to the HTTP status code description for 422. (e.g., "Unprocessable Entity"
).details
(any
): Additional details about the error, if any.1const { UnprocessableEntityError } = require("http-error-kit"); 2 3console.log( 4 new UnprocessableEntityError("Unprocessable Entity", { field: "email" }) 5); 6/* UnprocessableEntityError { 7 * statusCode: 422, 8 * message: "Unprocessable Entity", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 423, Locked.
message
(string
): The error message. Defaults to the HTTP status code description for 423. (e.g., "Locked"
).details
(any
): Additional details about the error, if any.1const { LockedError } = require("http-error-kit"); 2 3console.log(new LockedError("Locked", { field: "email" })); 4/* LockedError { 5 * statusCode: 423, 6 * message: "Locked", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 424, Failed Dependency.
message
(string
): The error message. Defaults to the HTTP status code description for 424. (e.g., "Failed Dependency"
).details
(any
): Additional details about the error, if any.1const { FailedDependencyError } = require("http-error-kit"); 2 3console.log(new FailedDependencyError("Failed Dependency", { field: "email" })); 4/* FailedDependencyError { 5 * statusCode: 424, 6 * message: "Failed Dependency", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 425, Too Early.
message
(string
): The error message. Defaults to the HTTP status code description for 425. (e.g., "Too Early"
).details
(any
): Additional details about the error, if any.1const { TooEarlyError } = require("http-error-kit"); 2 3console.log(new TooEarlyError("Too Early", { field: "email" })); 4/* TooEarlyError { 5 * statusCode: 425, 6 * message: "Too Early", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 426, Upgrade Required.
message
(string
): The error message. Defaults to the HTTP status code description for 426. (e.g., "Upgrade Required"
).details
(any
): Additional details about the error, if any.1const { UpgradeRequiredError } = require("http-error-kit"); 2 3console.log(new UpgradeRequiredError("Upgrade Required", { field: "email" })); 4/* UpgradeRequiredError { 5 * statusCode: 426, 6 * message: "Upgrade Required", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 428, Precondition Required.
message
(string
): The error message. Defaults to the HTTP status code description for 428. (e.g., "Precondition Required"
).details
(any
): Additional details about the error, if any.1const { PreconditionRequiredError } = require("http-error-kit"); 2 3console.log( 4 new PreconditionRequiredError("Precondition Required", { field: "email" }) 5); 6/* PreconditionRequiredError { 7 * statusCode: 428, 8 * message: "Precondition Required", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 429, Too Many Requests.
message
(string
): The error message. Defaults to the HTTP status code description for 429. (e.g., "Too Many Requests"
).details
(any
): Additional details about the error, if any.1const { TooManyRequestsError } = require("http-error-kit"); 2 3console.log(new TooManyRequestsError("Too Many Requests", { field: "email" })); 4/* TooManyRequestsError { 5 * statusCode: 429, 6 * message: "Too Many Requests", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 431, Request Header Fields Too Large.
message
(string
): The error message. Defaults to the HTTP status code description for 431. (e.g., "Request Header Fields Too Large"
).details
(any
): Additional details about the error, if any.1const { RequestHeaderFieldsTooLargeError } = require("http-error-kit"); 2 3console.log( 4 new RequestHeaderFieldsTooLargeError("Request Header Fields Too Large", { 5 field: "email", 6 }) 7); 8/* RequestHeaderFieldsTooLargeError { 9 * statusCode: 431, 10 * message: "Request Header Fields Too Large", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 451, Unavailable For Legal Reasons.
message
(string
): The error message. Defaults to the HTTP status code description for 451. (e.g., "Unavailable For Legal Reasons"
).details
(any
): Additional details about the error, if any.1const { UnavailableForLegalReasonsError } = require("http-error-kit"); 2 3console.log( 4 new UnavailableForLegalReasonsError("Unavailable For Legal Reasons", { 5 field: "email", 6 }) 7); 8/* UnavailableForLegalReasonsError { 9 * statusCode: 451, 10 * message: "Unavailable For Legal Reasons", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 500, Internal Server Error.
message
(string
): The error message. Defaults to the HTTP status code description for 500. (e.g., "Internal Server Error"
).details
(any
): Additional details about the error, if any.1const { InternalServerError } = require("http-error-kit"); 2 3console.log( 4 new InternalServerError("Internal Server Error", { field: "email" }) 5); 6/* InternalServerError { 7 * statusCode: 500, 8 * message: "Internal Server Error", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 501, Not Implemented.
message
(string
): The error message. Defaults to the HTTP status code description for 501. (e.g., "Not Implemented"
).details
(any
): Additional details about the error, if any.1const { NotImplementedError } = require("http-error-kit"); 2 3console.log(new NotImplementedError("Not Implemented", { field: "email" })); 4/* NotImplementedError { 5 * statusCode: 501, 6 * message: "Not Implemented", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 502, Bad Gateway.
message
(string
): The error message. Defaults to the HTTP status code description for 502. (e.g., "Bad Gateway"
).details
(any
): Additional details about the error, if any.1const { BadGatewayError } = require("http-error-kit"); 2 3console.log(new BadGatewayError("Bad Gateway", { field: "email" })); 4/* BadGatewayError { 5 * statusCode: 502, 6 * message: "Bad Gateway", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 503, Service Unavailable.
message
(string
): The error message. Defaults to the HTTP status code description for 503. (e.g., "Service Unavailable"
).details
(any
): Additional details about the error, if any.1const { ServiceUnavailableError } = require("http-error-kit"); 2 3console.log( 4 new ServiceUnavailableError("Service Unavailable", { field: "email" }) 5); 6/* ServiceUnavailableError { 7 * statusCode: 503, 8 * message: "Service Unavailable", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 504, Gateway Timeout.
message
(string
): The error message. Defaults to the HTTP status code description for 504. (e.g., "Gateway Timeout"
).details
(any
): Additional details about the error, if any.1const { GatewayTimeoutError } = require("http-error-kit"); 2 3console.log(new GatewayTimeoutError("Gateway Timeout", { field: "email" })); 4/* GatewayTimeoutError { 5 * statusCode: 504, 6 * message: "Gateway Timeout", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 505, HTTP Version Not Supported.
message
(string
): The error message. Defaults to the HTTP status code description for 505. (e.g., "HTTP Version Not Supported"
).details
(any
): Additional details about the error, if any.1const { HttpVersionNotSupportedError } = require("http-error-kit"); 2 3console.log( 4 new HttpVersionNotSupportedError("HTTP Version Not Supported", { 5 field: "email", 6 }) 7); 8/* HttpVersionNotSupportedError { 9 * statusCode: 505, 10 * message: "HTTP Version Not Supported", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 506, Variant Also Negotiates.
message
(string
): The error message. Defaults to the HTTP status code description for 506. (e.g., "Variant Also Negotiates"
).details
(any
): Additional details about the error, if any.1const { VariantAlsoNegotiatesError } = require("http-error-kit"); 2 3console.log( 4 new VariantAlsoNegotiatesError("Variant Also Negotiates", { 5 field: "email", 6 }) 7); 8/* VariantAlsoNegotiatesError { 9 * statusCode: 506, 10 * message: "Variant Also Negotiates", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Creates a new instance of the KitGeneralError class with a status code of 507, Insufficient Storage.
message
(string
): The error message. Defaults to the HTTP status code description for 507. (e.g., "Insufficient Storage"
).details
(any
): Additional details about the error, if any.1const { InsufficientStorageError } = require("http-error-kit"); 2 3console.log( 4 new InsufficientStorageError("Insufficient Storage", { field: "email" }) 5); 6/* InsufficientStorageError { 7 * statusCode: 507, 8 * message: "Insufficient Storage", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Creates a new instance of the KitGeneralError class with a status code of 508, Loop Detected.
message
(string
): The error message. Defaults to the HTTP status code description for 508. (e.g., "Loop Detected"
).details
(any
): Additional details about the error, if any.1const { LoopDetectedError } = require("http-error-kit"); 2 3console.log(new LoopDetectedError("Loop Detected", { field: "email" })); 4/* LoopDetectedError { 5 * statusCode: 508, 6 * message: "Loop Detected", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 510, Not Extended.
message
(string
): The error message. Defaults to the HTTP status code description for 510. (e.g., "Not Extended"
).details
(any
): Additional details about the error, if any.1const { NotExtendedError } = require("http-error-kit"); 2 3console.log(new NotExtendedError("Not Extended", { field: "email" })); 4/* NotExtendedError { 5 * statusCode: 510, 6 * message: "Not Extended", 7 * details: { 8 * field: "email" 9 * } 10 * } 11 */
Creates a new instance of the KitGeneralError class with a status code of 511, Network Authentication Required.
message
(string
): The error message. Defaults to the HTTP status code description for 511. (e.g., "Network Authentication Required"
).details
(any
): Additional details about the error, if any.1const { NetworkAuthenticationRequiredError } = require("http-error-kit"); 2 3console.log( 4 new NetworkAuthenticationRequiredError("Network Authentication Required", { 5 field: "email", 6 }) 7); 8/* NetworkAuthenticationRequiredError { 9 * statusCode: 511, 10 * message: "Network Authentication Required", 11 * details: { 12 * field: "email" 13 * } 14 * } 15 */
Represents a general error with a status code, message, and optional details.
✅ Available in:
http-error-kit
andhttp-error-kit/generic
statusCode
(number
): The HTTP status code associated with the error (e.g., 500
).message
(string
): A human-readable error message. (e.g., "Internal Server Error"
).details
(any
): Additional details about the error, if any.1const { KitGeneralError } = require("http-error-kit"); 2 3console.log( 4 new KitGeneralError(500, "Internal Server Error", { field: "email" }) 5); 6/* KitGeneralError { 7 * statusCode: 500, 8 * message: "Internal Server Error", 9 * details: { 10 * field: "email" 11 * } 12 * } 13 */
Represents a general error with a status code, message, and optional details.
✅ Available in:
http-error-kit
andhttp-error-kit/http
statusCode
(number
): The HTTP status code associated with the error (e.g., 500
).message
(string
): A human-readable error message. (e.g., "Internal Server Error"
).details
(any
): Additional details about the error, if any.1const formatter = (statusCode, message, details, ...args) => ({ 2 code: statusCode, 3 msg: message, 4 extra: details, 5 traceId: args[0] || "default-trace-id", 6}); 7 8console.log(new KitHttpError(400, "Bad Request", {}).setFormatter(formatter)); 9/* KitHttpError { 10 * code: 400, 11 * msg: "Invalid request", 12 * extra: { 13 * field: "email" 14 * }, 15 * traceId: "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a" 16 * } 17 */
The original author of the project is Himanshu Bansal
This is all voluntary work, so if you want to support my efforts you can
You can also use the following:
http-error-kit
project is open-sourced software licensed under the MIT license by Himanshu Bansal.
No vulnerabilities found.
@libj/http-meta
Http meta kit
@imraan-hendricks/error-kit
Error Kit is an NPM package that provides a collection of common custom error classes for TypeScript.
@randajan/api-kit
A lightweight wrapper around fetch that always returns a structured JSON response, handling errors and network issues gracefully
@nodesandbox/response-kit
A collection of TypeScript response and error handlers for Node.js (express) applications.