0.5.0 • Published 9 months ago

@error-handler/express v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Error handling utilities for Express.js

This package provides a set of utilities to handle errors in an Express.js application. It includes middleware for handling errors, a custom error class, and a utility function to create errors.

Installation

npm install @error-handler/express

Usage

import express from "express";

import { APIError, catchAsync, errorHandler } from "@error-handler/express";
// OR
// const { APIError, catchAsync, errorHandler } = require("@error-handler/express")

const app = express();

app.get(
  "/",
  catchAsync(async (req, res) => {
    throw new APIError.BadRequest("This throws a 400 status code error with the message written here");
  }),
);
// response
// {
//   "error": "This throws a 400 status code error with the message written here",
//   "success": false,
//   "data": {}
// }

app.use(errorHandler({ logErrors: true, defaultMessage: "Internal server error" }));

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});
0.5.0

9 months ago

0.4.0

10 months ago

0.3.0

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago