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

wavim/http-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Convenient HTTP Error Utilities

Topics

Resources

License

Stars

Watchers

Forks