From ed6252563d642978af10cd363de5113e0006f19f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 18 Sep 2019 20:29:52 +0200 Subject: Add error-handling middleware --- webserver.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webserver.js b/webserver.js index 319f392..14833b4 100755 --- a/webserver.js +++ b/webserver.js @@ -192,6 +192,14 @@ app.get("/goioi",function(req,res){ });*/ +// Error-handling middleware +app.use(function(err,req,res,next){ + var id=new Date().getTime().toString()+Math.random().toFixed(10).slice(2); + console.log("Error caught in app: (id="+id+")"); + console.log(err.stack); + res.status(500).end("An internal error occurred; it has been logged with id "+id+".\n"); +}); + var server=httpServer.listen(PORT,function(){ var host=server.address().address; var port=server.address().port; -- cgit v1.2.3-70-g09d2