Skip to the content.

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.

GitHub Workflow Status npm version GitHub license GitHub Issues Codacy Badge Codacy Badge npms.io (final) GitHub code size in bytes npm Socket Badge GitHub Pages Github Sponsors Open Collective Buy Me A Coffee Patreon PayPal

Features

Table of Content

Installation

npm install http-error-kit

Usage

1. Dynamic Formatting ( Default )

By default, importing error classes allows their format to be dynamically updated by changing the global formatter.

const { BadRequestError } = require("http-error-kit");
//
import { BadRequestError } from "http-error-kit";

console.log(new BadRequestError("Invalid request", { field: "email" }));
/*  BadRequestError {
 *      statusCode: 400,
 *      message: "Invalid request",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

After setting a global formatter, the same error class will follow the new structure defined by the formatter.

const { BadRequestError, KitHttpErrorConfig } = require("http-error-kit");
//
import { BadRequestError, KitHttpErrorConfig } from "http-error-kit";

const formatter = (statusCode, message, details, ...args) => ({
    code: statusCode,
    msg: message,
    extra: details,
    traceId: args[0] || "default-trace-id",
});

KitHttpErrorConfig.configureFormatter(formatter);

console.log(new BadRequestError("Invalid request", { field: "email" }));
/*  BadRequestError {
 *      code: 400,
 *      msg: "Invalid request",
 *      extra: {
 *          field: "email"
 *      },
 *      traceId: "default-trace-id"
 *  }
 */

2. Generic HTTP Errors

By default, if you import errors without any additional setup, you’ll get the generic error implementations.

const { BadRequestError } = require("http-error-kit");
//
import { BadRequestError } from "http-error-kit";

console.log(new BadRequestError("Invalid request", { field: "email" }));
/*  BadRequestError {
 *      statusCode: 400,
 *      message: "Invalid request",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

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:

const { BadRequestError } = require("http-error-kit/generic");

3. Standardized HTTP Errors (Configurable Formatting)

You can set a global formatter to customize the error structure across your application. To enable structured error responses, use KitHttpError with global configuration:

const { BadRequestError, KitHttpErrorConfig } = require("http-error-kit");

KitHttpErrorConfig.configureFormatter(
    (statusCode, message, details, ...args) => ({
        code: statusCode,
        msg: message,
        extra: details,
        traceId: args[0] || "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a",
    })
);

console.log(
    new BadRequestError("Invalid request", { field: "email" }, "trace-123")
);
/*  BadRequestError {
 *      code: 400,
 *      msg: "Invalid request",
 *      extra: {
 *          field: "email"
 *      },
 *      traceId: "trace-123"
 *  }
 */

Formatters

Using a Custom Error Formatter

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

Key Differences

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:

Types of Formatter

1. Global Formatter

You can define a global formatter to standardize the structure of all error instances.

const { KitHttpErrorConfig } = require("http-error-kit");

KitHttpErrorConfig.configureFormatter(
    (statusCode, message, details, ...args) => ({
        code: statusCode,
        msg: message,
        extra: details,
        traceId: args[0] || "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a",
    })
);

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.

2. Instance-Level Formatter Override

For specific cases, you can override the global formatter by setting an instance-level formatter.

const { BadRequestError } = require("http-error-kit/http");

const instanceFormatter = (statusCode, message, details, ...args) => ({
    errorCode: statusCode,
    errorMessage: message,
    errorDetails: details,
    requestId: args[0] || "instance-trace-id",
});

console.log(
    new BadRequestError(
        "Invalid request",
        { field: "email" },
        "trace-456"
    ).setFormatter(instanceFormatter)
);
/*  BadRequestError {
 *      errorCode: 400,
 *      errorMessage: "Invalid request",
 *      errorDetails: {
 *          field: "email"
 *      },
 *      requestId: "trace-456"
 *  }
 */

This will override the global formatter only for this instance

Error Kit Overview

Common Error Classes

1. Bad Request Error

Creates a new instance of the KitGeneralError class with a status code of 400, Bad Request.

Parameters
Example
const { BadRequestError } = require("http-error-kit");

console.log(new BadRequestError("Bad Request", { field: "email" }));
/*  BadRequestError {
 *      statusCode: 400,
 *      message: "Bad Request",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

2. Unauthorized Error

Creates a new instance of the KitGeneralError class with a status code of 401, Unauthorized.

Parameters
Example
const { UnauthorizedError } = require("http-error-kit");

console.log(new UnauthorizedError("Unauthorized", { field: "email" }));
/*  UnauthorizedError {
 *      statusCode: 401,
 *      message: "Unauthorized",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

3. Payment Required Error

Creates a new instance of the KitGeneralError class with a status code of 402, Payment Required.

Parameters
Example
const { PaymentRequiredError } = require("http-error-kit");

console.log(new PaymentRequiredError("Payment Required", { field: "email" }));
/*  PaymentRequiredError {
 *      statusCode: 402,
 *      message: "Payment Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

4. Forbidden Error

Creates a new instance of the KitGeneralError class with a status code of 403, Forbidden.

Parameters
Example
const { ForbiddenError } = require("http-error-kit");

console.log(new ForbiddenError("Forbidden", { field: "email" }));
/*  ForbiddenError {
 *      statusCode: 403,
 *      message: "Forbidden",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

5. Not Found Error

Creates a new instance of the KitGeneralError class with a status code of 404, Not Found.

Parameters
Example
const { NotFoundError } = require("http-error-kit");

console.log(new NotFoundError("Not Found", { field: "email" }));
/*  NotFoundError {
 *      statusCode: 404,
 *      message: "Not Found",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

6. Method Not Allowed Error

Creates a new instance of the KitGeneralError class with a status code of 405, Method Not Allowed.

Parameters
Example
const { MethodNotAllowedError } = require("http-error-kit");

console.log(
    new MethodNotAllowedError("Method Not Allowed", { field: "email" })
);
/*  MethodNotAllowedError {
 *      statusCode: 405,
 *      message: "Method Not Allowed",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

7. Not Acceptable Error

Creates a new instance of the KitGeneralError class with a status code of 406, Not Acceptable.

Parameters
Example
const { NotAcceptableError } = require("http-error-kit");

console.log(new NotAcceptableError("Not Acceptable", { field: "email" }));
/*  NotAcceptableError {
 *      statusCode: 406,
 *      message: "Not Acceptable",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

8. Proxy Authentication Required Error

Creates a new instance of the KitGeneralError class with a status code of 407, Proxy Authentication Required.

Parameters
Example
const { ProxyAuthenticationRequiredError } = require("http-error-kit");

console.log(
    new ProxyAuthenticationRequiredError("Proxy Authentication Required", {
        field: "email",
    })
);
/*  ProxyAuthenticationRequiredError {
 *      statusCode: 407,
 *      message: "Proxy Authentication Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

9. Request Timeout Error

Creates a new instance of the KitGeneralError class with a status code of 408, Request Timeout.

Parameters
Example
const { RequestTimeoutError } = require("http-error-kit");

console.log(new RequestTimeoutError("Request Timeout", { field: "email" }));
/*  RequestTimeoutError {
 *      statusCode: 408,
 *      message: "Request Timeout",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

10. Conflict Error

Creates a new instance of the KitGeneralError class with a status code of 409, Conflict.

Parameters
Example
const { ConflictError } = require("http-error-kit");

console.log(new ConflictError("Conflict", { field: "email" }));
/*  ConflictError {
 *      statusCode: 409,
 *      message: "Conflict",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

11. Gone Error

Creates a new instance of the KitGeneralError class with a status code of 410, Gone.

Parameters
Example
const { GoneError } = require("http-error-kit");

console.log(new GoneError("Gone", { field: "email" }));
/*  GoneError {
 *      statusCode: 410,
 *      message: "Gone",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

12. Length Required Error

Creates a new instance of the KitGeneralError class with a status code of 411, Length Required.

Parameters
Example
const { LengthRequiredError } = require("http-error-kit");

console.log(new LengthRequiredError("Length Required", { field: "email" }));
/*  LengthRequiredError {
 *      statusCode: 411,
 *      message: "Length Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

13. Precondition Failed Error

Creates a new instance of the KitGeneralError class with a status code of 412, Precondition Failed.

Parameters
Example
const { PreconditionFailedError } = require("http-error-kit");

console.log(
    new PreconditionFailedError("Precondition Failed", { field: "email" })
);
/*  PreconditionFailedError {
 *      statusCode: 412,
 *      message: "Precondition Failed",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

14. Request Entity Too Large Error

Creates a new instance of the KitGeneralError class with a status code of 413, Request Entity Too Large.

Parameters
Example
const { RequestTooLongError } = require("http-error-kit");

console.log(
    new RequestTooLongError("Request Entity Too Large", { field: "email" })
);
/*  RequestTooLongError {
 *      statusCode: 413,
 *      message: "Request Entity Too Large",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

15. Request-URI Too Long Error

Creates a new instance of the KitGeneralError class with a status code of 414, Request-URI Too Long.

Parameters
Example
const { RequestUriTooLongError } = require("http-error-kit");

console.log(
    new RequestUriTooLongError("Request-URI Too Long", { field: "email" })
);
/*  RequestUriTooLongError {
 *      statusCode: 414,
 *      message: "Request-URI Too Long",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

16. Unsupported Media Type Error

Creates a new instance of the KitGeneralError class with a status code of 415, Unsupported Media Type.

Parameters
Example
const { UnsupportedMediaTypeError } = require("http-error-kit");

console.log(
    new UnsupportedMediaTypeError("Unsupported Media Type", { field: "email" })
);
/*  UnsupportedMediaTypeError {
 *      statusCode: 415,
 *      message: "Unsupported Media Type",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

17. Requested Range Not Satisfiable Error

Creates a new instance of the KitGeneralError class with a status code of 416, Requested Range Not Satisfiable.

Parameters
Example
const { RequestedRangeNotSatisfiableError } = require("http-error-kit");

console.log(
    new RequestedRangeNotSatisfiableError("Requested Range Not Satisfiable", {
        field: "email",
    })
);
/*  RequestedRangeNotSatisfiableError {
 *      statusCode: 416,
 *      message: "Requested Range Not Satisfiable",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

18. Expectation Failed Error

Creates a new instance of the KitGeneralError class with a status code of 417, Expectation Failed.

Parameters
Example
const { ExpectationFailedError } = require("http-error-kit");

console.log(
    new ExpectationFailedError("Expectation Failed", { field: "email" })
);
/*  ExpectationFailedError {
 *      statusCode: 417,
 *      message: "Expectation Failed",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

19. I’m a teapot Error

Creates a new instance of the KitGeneralError class with a status code of 418, I’m a teapot.

Parameters
Example
const { ImATeapotError } = require("http-error-kit");

console.log(new ImATeapotError("I'm a teapot", { field: "email" }));
/*  ImATeapotError {
 *      statusCode: 418,
 *      message: "I'm a teapot",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

20. Insufficient Space on Resource Error

Creates a new instance of the KitGeneralError class with a status code of 419, Insufficient Space on Resource.

Parameters
Example
const { InsufficientSpaceOnResourceError } = require("http-error-kit");

console.log(
    new InsufficientSpaceOnResourceError("Insufficient Space on Resource", {
        field: "email",
    })
);
/*  InsufficientSpaceOnResourceError {
 *      statusCode: 419,
 *      message: "Insufficient Space on Resource",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

21. Method Failure Error

Creates a new instance of the KitGeneralError class with a status code of 420, Method Failure.

Parameters
Example
const { MethodFailureError } = require("http-error-kit");

console.log(new MethodFailureError("Method Failure", { field: "email" }));
/*  MethodFailureError {
 *      statusCode: 420,
 *      message: "Method Failure",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

22. Misdirected Request Error

Creates a new instance of the KitGeneralError class with a status code of 421, Misdirected Request.

Parameters
Example
const { MisdirectedRequestError } = require("http-error-kit");

console.log(
    new MisdirectedRequestError("Misdirected Request", { field: "email" })
);
/*  MisdirectedRequestError {
 *      statusCode: 421,
 *      message: "Misdirected Request",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

23. Unprocessable Entity Error

Creates a new instance of the KitGeneralError class with a status code of 422, Unprocessable Entity.

Parameters
Example
const { UnprocessableEntityError } = require("http-error-kit");

console.log(
    new UnprocessableEntityError("Unprocessable Entity", { field: "email" })
);
/*  UnprocessableEntityError {
 *      statusCode: 422,
 *      message: "Unprocessable Entity",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

24. Locked Error

Creates a new instance of the KitGeneralError class with a status code of 423, Locked.

Parameters
Example
const { LockedError } = require("http-error-kit");

console.log(new LockedError("Locked", { field: "email" }));
/*  LockedError {
 *      statusCode: 423,
 *      message: "Locked",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

25. Failed Dependency Error

Creates a new instance of the KitGeneralError class with a status code of 424, Failed Dependency.

Parameters
Example
const { FailedDependencyError } = require("http-error-kit");

console.log(new FailedDependencyError("Failed Dependency", { field: "email" }));
/*  FailedDependencyError {
 *      statusCode: 424,
 *      message: "Failed Dependency",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

26. Too Early Error

Creates a new instance of the KitGeneralError class with a status code of 425, Too Early.

Parameters
Example
const { TooEarlyError } = require("http-error-kit");

console.log(new TooEarlyError("Too Early", { field: "email" }));
/*  TooEarlyError {
 *      statusCode: 425,
 *      message: "Too Early",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

27. Upgrade Required Error

Creates a new instance of the KitGeneralError class with a status code of 426, Upgrade Required.

Parameters
Example
const { UpgradeRequiredError } = require("http-error-kit");

console.log(new UpgradeRequiredError("Upgrade Required", { field: "email" }));
/*  UpgradeRequiredError {
 *      statusCode: 426,
 *      message: "Upgrade Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

28. Precondition Required Error

Creates a new instance of the KitGeneralError class with a status code of 428, Precondition Required.

Parameters
Example
const { PreconditionRequiredError } = require("http-error-kit");

console.log(
    new PreconditionRequiredError("Precondition Required", { field: "email" })
);
/*  PreconditionRequiredError {
 *      statusCode: 428,
 *      message: "Precondition Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

29. Too Many Requests Error

Creates a new instance of the KitGeneralError class with a status code of 429, Too Many Requests.

Parameters
Example
const { TooManyRequestsError } = require("http-error-kit");

console.log(new TooManyRequestsError("Too Many Requests", { field: "email" }));
/*  TooManyRequestsError {
 *      statusCode: 429,
 *      message: "Too Many Requests",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

30. Request Header Fields Too Large Error

Creates a new instance of the KitGeneralError class with a status code of 431, Request Header Fields Too Large.

Parameters
Example
const { RequestHeaderFieldsTooLargeError } = require("http-error-kit");

console.log(
    new RequestHeaderFieldsTooLargeError("Request Header Fields Too Large", {
        field: "email",
    })
);
/*  RequestHeaderFieldsTooLargeError {
 *      statusCode: 431,
 *      message: "Request Header Fields Too Large",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

Creates a new instance of the KitGeneralError class with a status code of 451, Unavailable For Legal Reasons.

Parameters
Example
const { UnavailableForLegalReasonsError } = require("http-error-kit");

console.log(
    new UnavailableForLegalReasonsError("Unavailable For Legal Reasons", {
        field: "email",
    })
);
/*  UnavailableForLegalReasonsError {
 *      statusCode: 451,
 *      message: "Unavailable For Legal Reasons",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

32. Internal Server Error

Creates a new instance of the KitGeneralError class with a status code of 500, Internal Server Error.

Parameters
Example
const { InternalServerError } = require("http-error-kit");

console.log(
    new InternalServerError("Internal Server Error", { field: "email" })
);
/*  InternalServerError {
 *      statusCode: 500,
 *      message: "Internal Server Error",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

33. Not Implemented Error

Creates a new instance of the KitGeneralError class with a status code of 501, Not Implemented.

Parameters
Example
const { NotImplementedError } = require("http-error-kit");

console.log(new NotImplementedError("Not Implemented", { field: "email" }));
/*  NotImplementedError {
 *      statusCode: 501,
 *      message: "Not Implemented",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

34. Bad Gateway Error

Creates a new instance of the KitGeneralError class with a status code of 502, Bad Gateway.

Parameters
Example
const { BadGatewayError } = require("http-error-kit");

console.log(new BadGatewayError("Bad Gateway", { field: "email" }));
/*  BadGatewayError {
 *      statusCode: 502,
 *      message: "Bad Gateway",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

35. Service Unavailable Error

Creates a new instance of the KitGeneralError class with a status code of 503, Service Unavailable.

Parameters
Example
const { ServiceUnavailableError } = require("http-error-kit");

console.log(
    new ServiceUnavailableError("Service Unavailable", { field: "email" })
);
/*  ServiceUnavailableError {
 *      statusCode: 503,
 *      message: "Service Unavailable",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

36. Gateway Timeout Error

Creates a new instance of the KitGeneralError class with a status code of 504, Gateway Timeout.

Parameters
Example
const { GatewayTimeoutError } = require("http-error-kit");

console.log(new GatewayTimeoutError("Gateway Timeout", { field: "email" }));
/*  GatewayTimeoutError {
 *      statusCode: 504,
 *      message: "Gateway Timeout",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

37. HTTP Version Not Supported Error

Creates a new instance of the KitGeneralError class with a status code of 505, HTTP Version Not Supported.

Parameters
Example
const { HttpVersionNotSupportedError } = require("http-error-kit");

console.log(
    new HttpVersionNotSupportedError("HTTP Version Not Supported", {
        field: "email",
    })
);
/*  HttpVersionNotSupportedError {
 *      statusCode: 505,
 *      message: "HTTP Version Not Supported",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

38. Variant Also Negotiates Error

Creates a new instance of the KitGeneralError class with a status code of 506, Variant Also Negotiates.

Parameters
Example
const { VariantAlsoNegotiatesError } = require("http-error-kit");

console.log(
    new VariantAlsoNegotiatesError("Variant Also Negotiates", {
        field: "email",
    })
);
/*  VariantAlsoNegotiatesError {
 *      statusCode: 506,
 *      message: "Variant Also Negotiates",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

39. Insufficient Storage Error

Creates a new instance of the KitGeneralError class with a status code of 507, Insufficient Storage.

Parameters
Example
const { InsufficientStorageError } = require("http-error-kit");

console.log(
    new InsufficientStorageError("Insufficient Storage", { field: "email" })
);
/*  InsufficientStorageError {
 *      statusCode: 507,
 *      message: "Insufficient Storage",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

40. Loop Detected Error

Creates a new instance of the KitGeneralError class with a status code of 508, Loop Detected.

Parameters
Example
const { LoopDetectedError } = require("http-error-kit");

console.log(new LoopDetectedError("Loop Detected", { field: "email" }));
/*  LoopDetectedError {
 *      statusCode: 508,
 *      message: "Loop Detected",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

41. Not Extended Error

Creates a new instance of the KitGeneralError class with a status code of 510, Not Extended.

Parameters
Example
const { NotExtendedError } = require("http-error-kit");

console.log(new NotExtendedError("Not Extended", { field: "email" }));
/*  NotExtendedError {
 *      statusCode: 510,
 *      message: "Not Extended",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

42. Network Authentication Required Error

Creates a new instance of the KitGeneralError class with a status code of 511, Network Authentication Required.

Parameters
Example
const { NetworkAuthenticationRequiredError } = require("http-error-kit");

console.log(
    new NetworkAuthenticationRequiredError("Network Authentication Required", {
        field: "email",
    })
);
/*  NetworkAuthenticationRequiredError {
 *      statusCode: 511,
 *      message: "Network Authentication Required",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

Special Error Classes

43. Kit General Error

Represents a general error with a status code, message, and optional details.

Available in: http-error-kit and http-error-kit/generic

Parameters
Example
const { KitGeneralError } = require("http-error-kit");

console.log(
    new KitGeneralError(500, "Internal Server Error", { field: "email" })
);
/*  KitGeneralError {
 *      statusCode: 500,
 *      message: "Internal Server Error",
 *      details: {
 *          field: "email"
 *      }
 *  }
 */

44. Kit Http Error

Represents a general error with a status code, message, and optional details.

Available in: http-error-kit and http-error-kit/http

Parameters
Example
const formatter = (statusCode, message, details, ...args) => ({
    code: statusCode,
    msg: message,
    extra: details,
    traceId: args[0] || "default-trace-id",
});

console.log(new KitHttpError(400, "Bad Request", {}).setFormatter(formatter));
/*  KitHttpError {
 *      code: 400,
 *      msg: "Invalid request",
 *      extra: {
 *          field: "email"
 *      },
 *      traceId: "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a"
 *  }
 */

People

The original author of the project is Himanshu Bansal

Donations

This is all voluntary work, so if you want to support my efforts you can

You can also use the following:

BTC: qzqmpxux3m56qqhz465u8022q9z63w2sysq4u9ltwj

ETH: 0x1D59a291391a3CE17C63D5dC50F258Dc0Ab62889

License

http-error-kit project is open-sourced software licensed under the MIT license by Himanshu Bansal.