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

This commit is contained in:
Jake 2015-07-16 17:48:48 -05:00
parent d71d99fa9a
commit b1cdf61e4b
6 changed files with 11 additions and 8 deletions

View File

@ -77,7 +77,10 @@ module.exports = function(request, response, result) {
return; 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.writeHead(422, headers);
response.end(result.body); response.end(result.body);
} else if (result.status === -1) { } else if (result.status === -1) {

View File

@ -52,7 +52,7 @@ 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: -2, status: -3,
body: "Invalid URL Path" body: "Invalid URL Path"
}); });
return; return;

View File

@ -11,7 +11,7 @@ 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: -2, status: -3,
body: "Invalid URL Path" body: "Invalid URL Path"
}); });
return; return;

View File

@ -62,7 +62,7 @@ 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: -2, status: -3,
body: "Invalid URL Path" body: "Invalid URL Path"
}); });
return; return;

View File

@ -59,7 +59,7 @@ 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: -2, status: -3,
body: "Invalid URL Path" body: "Invalid URL Path"
}); });
return; return;

View File

@ -859,10 +859,10 @@ describe("Crafatar", function() {
}); });
}); });
it("should return a 422 (invalid request path " + location + ")", function(done) { it("should return a 404 (invalid request path " + location + ")", function(done) {
request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid/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, 422); assert.strictEqual(res.statusCode, 404);
done(); done();
}); });
}); });