Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

express-async-patch

Express doesn't handle async errors by default unfortunately, here's a quick and easy solution!

MIT Licensed - Have fun and use however you like!

Installation

npm i -S https://gitlab.com/Eeveeboo/express-async-patch.git
# or
yarn add https://gitlab.com/Eeveeboo/express-async-patch.git

Usage

importexpressfrom'express';importexpressAsyncPatchfrom'./express-async-patch';// The patch needs to be called BEFORE you create a router or appexpressAsyncPatch((err,req,res,next)=>{// This is how I like to handle errors, you can implement any function you like here.if(req.path.indexOf("/api")==0)// Send JSON error responseres.status(501).json({status: false,message: err.message,data: err.stack});else// Send Express error responsenext(err);});constapp=express();// Normally this would just result in the webpage hangingapp.use(async(req,res)=>{thrownewError("Async Error Test.");});

About

Fork of GitLab original

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages