[MISC] Improve console logs and error handling a little.

This commit is contained in:
Jan Philipp Timme 2013-09-14 23:31:17 +02:00
parent 11c262cb03
commit 1602c7bd4e
1 changed files with 11 additions and 4 deletions

15
app.js
View File

@ -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