@wavim/http-error
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

HTTP Error

Convenient HTTP Error Utilities


Usage

Enjoy hassle-free HTTP error status handling:

import { ErrorCode, HttpError } from "@wavim/http-error";

// Map ErrorCode
ErrorCode[404]; // NOT_FOUND
ErrorCode.NOT_FOUND; // 404

// Get HttpError
throw new HttpError(404, "Missing Page");
throw new HttpError("NOT_FOUND", "Missing Page");

// ->
error.status; // 404
error.phrase; // NOT_FOUND
error.message; // Missing Page

// Handle HttpError
if (error instanceof HttpError) {
  switch (error.phrase) {
    // ...
  }

  res.status(error.status).send(error.message);
}

Readme

Keywords

none

Package Sidebar

Install

npm i @wavim/http-error

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

8.54 kB

Total Files

6

Last publish

Collaborators

  • carbonsoda