fix #22, caused by @e6481e3

This commit is contained in:
jomo 2014-11-29 17:15:59 +01:00
parent 452bb14605
commit 3d708d2342
2 changed files with 16 additions and 15 deletions

View File

@ -38,20 +38,18 @@ var get_username_url = function(name, callback) {
} else if (error) { } else if (error) {
callback(error, null); callback(error, null);
} else if (response.statusCode == 404) { } else if (response.statusCode == 404) {
// skin doesn't exist // skin (or user) doesn't exist
logging.log(name + " has no skin"); logging.log(name + " has no skin");
callback(0, null); callback(null, null);
} else if (response.statusCode == 429) { } else if (response.statusCode == 429) {
// Too Many Requests // Too Many Requests
// Never got this, seems like skins aren't limited // Never got this, seems like skins aren't limited
logging.warn(name + " Too many requests"); logging.warn(body || "Too many requests");
logging.warn(body);
callback(null, null); callback(null, null);
} else { } else {
logging.error(name + " Unknown error:"); logging.error(name + " Unknown error:");
logging.error(response); logging.error(response);
logging.error(body); callback(body || "Unknown error", null);
callback(null, null);
} }
}); });
}; };
@ -72,17 +70,14 @@ var get_uuid_url = function(uuid, callback) {
} else if (response.statusCode == 204 || response.statusCode == 404) { } else if (response.statusCode == 204 || response.statusCode == 404) {
// we get 204 No Content when UUID doesn't exist (including 404 in case they change that) // we get 204 No Content when UUID doesn't exist (including 404 in case they change that)
logging.log(uuid + " uuid does not exist"); logging.log(uuid + " uuid does not exist");
callback(0, null); callback(null, null);
} else if (response.statusCode == 429) { } else if (response.statusCode == 429) {
// Too Many Requests // Too Many Requests
logging.warn(uuid + " Too many requests"); callback(body || "Too many requests", null);
logging.warn(body);
callback(null, null);
} else { } else {
logging.error(uuid + " Unknown error:"); logging.error(uuid + " Unknown error:");
logging.error(response); logging.error(response);
logging.error(body); callback(body || "Unknown error", null);
callback(null, null);
} }
}); });
}; };

View File

@ -64,13 +64,13 @@ describe('Crafatar', function() {
}); });
it("should not exist (uuid)", function(done) { it("should not exist (uuid)", function(done) {
networking.get_skin_url("00000000000000000000000000000000", function(err, profile) { networking.get_skin_url("00000000000000000000000000000000", function(err, profile) {
assert.strictEqual(err, 0); assert.strictEqual(err, null);
done(); done();
}); });
}); });
it("should not exist (username)", function(done) { it("should not exist (username)", function(done) {
networking.get_skin_url("Steve", function(err, profile) { networking.get_skin_url("Steve", function(err, profile) {
assert.strictEqual(err, 0); assert.strictEqual(err, null);
done(); done();
}); });
}); });
@ -154,8 +154,14 @@ describe('Crafatar', function() {
before(function() { before(function() {
cache.get_redis().flushall(); cache.get_redis().flushall();
}); });
it("should be rate limited", function(done) { it("should be rate limited (uuid)", function(done) {
helpers.get_avatar(uuid, false, 160, function(err, status, image) { helpers.get_avatar(uuid, false, 160, function(err, status, image) {
assert.strictEqual(JSON.parse(err).error, "TooManyRequestsException");
done();
});
});
it("should NOT be rate limited (username)", function(done) {
helpers.get_avatar(username, false, 160, function(err, status, image) {
assert.strictEqual(err, null); assert.strictEqual(err, null);
done(); done();
}); });