[TASK] Change http response codes.

I feel this needs a bit more explanation:
I plan to answer all requests with http status code 200 OK
and indicate the success in the actual JSON response.

It is still ugly as hell, but it might be like that for a while.
This commit is contained in:
Jan Philipp Timme 2013-09-16 21:56:12 +02:00
parent b121210533
commit 17e6b0aa70
2 changed files with 4 additions and 3 deletions

5
app.js
View File

@ -73,13 +73,14 @@ app.use("/session", new sessionAPIHandler(db));
//API: /user //API: /user
app.use("/user", new userAPIHandler(db)); app.use("/user", new userAPIHandler(db));
//define 404 for everything else or 500 on error (ugly but i think it's useful) //'automatic' error handling and/or responding to non-implemented http calls
//i know this is ugly as hell, but it might stay for a while.
app.use(function(err, req, res, next) { app.use(function(err, req, res, next) {
if(err) { if(err) {
console.log(err.stack); console.log(err.stack);
res.send(500, "Oops, an error occured."); res.send(500, "Oops, an error occured.");
} else { } else {
res.send(404, "Sorry, nothing here."); res.send(501, "Method not implemented");
} }
res.end(); res.end();
}); });

View File

@ -10,7 +10,7 @@ var constructor = function(db) {
if(req.method == "PUT") { if(req.method == "PUT") {
var params = req.body; var params = req.body;
if(tools.reqParamsGiven(["username", "password", "email"], params) == false) { if(tools.reqParamsGiven(["username", "password", "email"], params) == false) {
res.send(500, JSON.stringify({ res.send(200, JSON.stringify({
"success": false, "success": false,
"err": "This method needs username, password and email!" "err": "This method needs username, password and email!"
})); }));