From 1602c7bd4e267606a363de1cf2d2b861ec907f0a Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sat, 14 Sep 2013 23:31:17 +0200 Subject: [PATCH] [MISC] Improve console logs and error handling a little. --- app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 4d8b7aa..81b394b 100644 --- a/app.js +++ b/app.js @@ -17,12 +17,13 @@ var db = couch.database(settings.couchdb.database); db.exists(function(err, exists) { if(err) { + console.log("An error occured - could not talk to couchdb:"); console.log(err); process.exit(1); } else if(exists == true) { console.log("Database exists :-)"); } else { - console.log("Database does not exist!"); + console.log("Database does not exist :-("); process.exit(1); } }); @@ -89,9 +90,15 @@ app.use("/session", function(req, res) { } }); -//define 404 for everything else (ugly but i think it's useful) -app.use(function(req, res) { - res.status(404).send("Sorry, nothing here."); +//define 404 for everything else or 500 on error (ugly but i think it's useful) +app.use(function(err, req, res, next) { + if(err) { + console.log(err.stack); + res.send(500, "Oops, an error occured."); + } else { + res.send(404, "Sorry, nothing here."); + } + res.end(); }); //fire it up as https (or http) server