summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwebserver.js8
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;