Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-error-catcher

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-error-catcher

async error handler

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
decreased by-8.94%
Maintainers
2
Weekly downloads
 
Created
Source

express-error-catcher

The express-error-catcher npm package provides a convenient solution for managing async/await errors in Node.js Express applications. The package is designed with simplicity in mind. Below are instructions on how to integrate and utilize express-error-catcher in your projects.

Why Use express-error-catcher?

  • Elimination of the need for extensive try-catch blocks in your asynchronous code.
  • You can keep your route handlers clean and free from error-handling clutter.
  • Enhances the readability of your code.
  • Streamlines the development process.

Installation

To install express-error-catcher, use the following npm command:

npm install express-error-catcher

Example

import express from "express";
import {
  asyncErrorHandler,
  error,
  Response,
  Error,
} from "express-error-catcher";

const app = express();

// Error middleware for asyncErrorHandler to work
app.use(error);

// Example route with asyncErrorHandler
app.get(
  "/name",
  asyncErrorHandler((req) => {
    // Throwing an error
    throw Error("Error while retrieving name", 500);

    // Returning a response
    return Response("Successfully retrieved name", { name: "Daisy" }, 200);
  })
);

// Start the Express app
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

How does this work?

Keywords

FAQs

Package last updated on 02 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc