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!
npm i -S https://gitlab.com/Eeveeboo/express-async-patch.git
# or
yarn add https://gitlab.com/Eeveeboo/express-async-patch.gitimportexpressfrom'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.");});