Browse Source

use status -2 for 404s

human_status (response.js) defines code -2 as 'user error'. 404 is definitely a user error, so using that makes sense.
eventually we should change the whole status code thing with #120
jomo 10 years ago
parent
commit
607dcaf6e5
6 changed files with 15 additions and 14 deletions
  1. 2 5
      lib/response.js
  2. 3 2
      lib/routes/avatars.js
  3. 3 2
      lib/routes/capes.js
  4. 3 2
      lib/routes/renders.js
  5. 3 2
      lib/routes/skins.js
  6. 1 1
      test/test.js

+ 2 - 5
lib/response.js

@@ -77,11 +77,8 @@ module.exports = function(request, response, result) {
     return;
     return;
   }
   }
 
 
-  if (result.status === -3) {
-    response.writeHead(404, headers);
-    response.end(result.body);
-  } else if (result.status === -2) {
-    response.writeHead(422, headers);
+  if (result.status === -2) {
+    response.writeHead(result.code || 422, headers);
     response.end(result.body);
     response.end(result.body);
   } else if (result.status === -1) {
   } else if (result.status === -1) {
     response.writeHead(500, headers);
     response.writeHead(500, headers);

+ 3 - 2
lib/routes/avatars.js

@@ -52,8 +52,9 @@ module.exports = function(req, callback) {
   // check for extra paths
   // check for extra paths
   if (req.url.path_list.length > 2) {
   if (req.url.path_list.length > 2) {
     callback({
     callback({
-      status: -3,
-      body: "Invalid URL Path"
+      status: -2,
+      body: "Invalid Path",
+      code: 404
     });
     });
     return;
     return;
   }
   }

+ 3 - 2
lib/routes/capes.js

@@ -11,8 +11,9 @@ module.exports = function(req, callback) {
   // check for extra paths
   // check for extra paths
   if (req.url.path_list.length > 2) {
   if (req.url.path_list.length > 2) {
     callback({
     callback({
-      status: -3,
-      body: "Invalid URL Path"
+      status: -2,
+      body: "Invalid Path",
+      code: 404
     });
     });
     return;
     return;
   }
   }

+ 3 - 2
lib/routes/renders.js

@@ -62,8 +62,9 @@ module.exports = function(req, callback) {
   // check for extra paths
   // check for extra paths
   if (req.url.path_list.length > 3) {
   if (req.url.path_list.length > 3) {
     callback({
     callback({
-      status: -3,
-      body: "Invalid URL Path"
+      status: -2,
+      body: "Invalid Path",
+      code: 404
     });
     });
     return;
     return;
   }
   }

+ 3 - 2
lib/routes/skins.js

@@ -59,8 +59,9 @@ module.exports = function(req, callback) {
   // check for extra paths
   // check for extra paths
   if (req.url.path_list.length > 2) {
   if (req.url.path_list.length > 2) {
     callback({
     callback({
-      status: -3,
-      body: "Invalid URL Path"
+      status: -2,
+      body: "Invalid Path",
+      code: 404
     });
     });
     return;
     return;
   }
   }

+ 1 - 1
test/test.js

@@ -859,7 +859,7 @@ describe("Crafatar", function() {
           });
           });
         });
         });
 
 
-        it("should return a 404 (invalid request path " + location + ")", function(done) {
+        it("should return a 404 (invalid path " + location + ")", function(done) {
           request.get("http://localhost:3000/" + location + "/853c80ef3c3749fdaa49938b674adae6/invalid", function(error, res, body) {
           request.get("http://localhost:3000/" + location + "/853c80ef3c3749fdaa49938b674adae6/invalid", function(error, res, body) {
             assert.ifError(error);
             assert.ifError(error);
             assert.strictEqual(res.statusCode, 404);
             assert.strictEqual(res.statusCode, 404);