[MISC] Improve console logs and error handling a little.
This commit is contained in:
parent
11c262cb03
commit
1602c7bd4e
15
app.js
15
app.js
|
@ -17,12 +17,13 @@ var db = couch.database(settings.couchdb.database);
|
||||||
|
|
||||||
db.exists(function(err, exists) {
|
db.exists(function(err, exists) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
console.log("An error occured - could not talk to couchdb:");
|
||||||
console.log(err);
|
console.log(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if(exists == true) {
|
} else if(exists == true) {
|
||||||
console.log("Database exists :-)");
|
console.log("Database exists :-)");
|
||||||
} else {
|
} else {
|
||||||
console.log("Database does not exist!");
|
console.log("Database does not exist :-(");
|
||||||
process.exit(1);
|
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)
|
//define 404 for everything else or 500 on error (ugly but i think it's useful)
|
||||||
app.use(function(req, res) {
|
app.use(function(err, req, res, next) {
|
||||||
res.status(404).send("Sorry, nothing here.");
|
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
|
//fire it up as https (or http) server
|
||||||
|
|
Loading…
Reference in New Issue