1.1.0 • Published 7 days ago

@mrcaidev/http-errors v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

@mrcaidev/http-errors

Utility classes for HTTP errors.

📦 Installation

npm i @mrcaidev/http-errors

🛠️ Usage

Default:

import { BadRequestError } from "@mrcaidev/http-errors";

throw new BadRequestError(); // status: 400, message: "Bad Request"

Customized error message:

import { BadRequestError } from "@mrcaidev/http-errors";

throw new BadRequestError("Malformed data"); // status: 400, message: "Malformed data"

Dynamic status code:

import { HttpError } from "@mrcaidev/http-errors";

throw new HttpError(400); // status: 400, message: "Bad Request"

Dynamic status code and customized error message:

import { HttpError } from "@mrcaidev/http-errors";

throw new HttpError(400, "Malformed data"); // status: 400, message: "Malformed data"

All error classes extend HttpError, which further extends Error.

import { BadRequestError, HttpError } from "@mrcaidev/http-errors";

new BadRequestError() instanceof HttpError; // true
new HttpError(400) instanceof Error; // true

Hover the mouse over the error class to view its definition and RFC link.

Hover tooltip

🔎 References

📜 License

MIT

1.1.0

7 days ago

1.0.0

9 months ago