Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Latest commit

 

History

History
34 lines (25 loc) · 639 Bytes

File metadata and controls

34 lines (25 loc) · 639 Bytes

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);
}