Socket
Socket
Sign inDemoInstall

express-async-error-patch

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-async-error-patch

let express support async middleware error catch


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

express-async-error-patch

let express support async middleware/router error catch

Usage

const express=require('express');
const app=express();

const asyncPatch=require('express-async-error-patch');
asyncPatch(app);
//done

Then you can handle async middleware errors in your normal error handle as same as sync middlewares.

app.get('/',async (req,res,next)=>{
	await new Promise((resolve,reject)=>{
		setTimeout(()=>{//do an async operation
			reject('test');//reject in 1 second
		},1000);
	});
});

app.use((err,req,res,next)=>{
	//the rejected promise error will be passed to this normal error handle
	console.log(err);// "test"
})

How

This patcher simply add an "await" and an "async" to the express Layer.prototype.handle_request function to let all router and middleware support async errors.

Notice

This patcher modifies just one express source function and have been tested in express 4.x, not sure will it work in lower or higher versions.

Keywords

FAQs

Last updated on 20 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc