瀏覽代碼

Change invalid request path to be a 404 rather than 422, implement status id in response module

Jake 10 年之前
父節點
當前提交
b1cdf61e4b
共有 6 個文件被更改,包括 11 次插入8 次删除
  1. 4 1
      lib/response.js
  2. 1 1
      lib/routes/avatars.js
  3. 1 1
      lib/routes/capes.js
  4. 1 1
      lib/routes/renders.js
  5. 1 1
      lib/routes/skins.js
  6. 3 3
      test/test.js

+ 4 - 1
lib/response.js

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

+ 1 - 1
lib/routes/avatars.js

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

+ 1 - 1
lib/routes/capes.js

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

+ 1 - 1
lib/routes/renders.js

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

+ 1 - 1
lib/routes/skins.js

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

+ 3 - 3
test/test.js

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