From 17e6b0aa701cf3c444d049d6c59a2ca0fad86894 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 16 Sep 2013 21:56:12 +0200 Subject: [PATCH] [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. --- app.js | 5 +++-- src/User.api.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index e3e6620..7f19ed4 100644 --- a/app.js +++ b/app.js @@ -73,13 +73,14 @@ app.use("/session", new sessionAPIHandler(db)); //API: /user 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) { if(err) { console.log(err.stack); res.send(500, "Oops, an error occured."); } else { - res.send(404, "Sorry, nothing here."); + res.send(501, "Method not implemented"); } res.end(); }); diff --git a/src/User.api.js b/src/User.api.js index 3f3f678..cb4b575 100644 --- a/src/User.api.js +++ b/src/User.api.js @@ -10,7 +10,7 @@ var constructor = function(db) { if(req.method == "PUT") { var params = req.body; if(tools.reqParamsGiven(["username", "password", "email"], params) == false) { - res.send(500, JSON.stringify({ + res.send(200, JSON.stringify({ "success": false, "err": "This method needs username, password and email!" }));