diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-09-18 20:29:52 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-09-18 20:33:47 +0200 |
commit | ed6252563d642978af10cd363de5113e0006f19f (patch) | |
tree | 7396824eb9170c30f5986ca45c43634e068deb6d | |
parent | 010668be042bca3349785b54ab58ba4793239556 (diff) |
Add error-handling middleware
-rwxr-xr-x | webserver.js | 8 |
1 files changed, 8 insertions, 0 deletions
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; |