mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
fix #22, caused by @e6481e3
This commit is contained in:
parent
452bb14605
commit
3d708d2342
@ -38,20 +38,18 @@ var get_username_url = function(name, callback) {
|
||||
} else if (error) {
|
||||
callback(error, null);
|
||||
} else if (response.statusCode == 404) {
|
||||
// skin doesn't exist
|
||||
// skin (or user) doesn't exist
|
||||
logging.log(name + " has no skin");
|
||||
callback(0, null);
|
||||
callback(null, null);
|
||||
} else if (response.statusCode == 429) {
|
||||
// Too Many Requests
|
||||
// Never got this, seems like skins aren't limited
|
||||
logging.warn(name + " Too many requests");
|
||||
logging.warn(body);
|
||||
logging.warn(body || "Too many requests");
|
||||
callback(null, null);
|
||||
} else {
|
||||
logging.error(name + " Unknown error:");
|
||||
logging.error(response);
|
||||
logging.error(body);
|
||||
callback(null, null);
|
||||
callback(body || "Unknown error", null);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -72,17 +70,14 @@ var get_uuid_url = function(uuid, callback) {
|
||||
} 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)
|
||||
logging.log(uuid + " uuid does not exist");
|
||||
callback(0, null);
|
||||
callback(null, null);
|
||||
} else if (response.statusCode == 429) {
|
||||
// Too Many Requests
|
||||
logging.warn(uuid + " Too many requests");
|
||||
logging.warn(body);
|
||||
callback(null, null);
|
||||
callback(body || "Too many requests", null);
|
||||
} else {
|
||||
logging.error(uuid + " Unknown error:");
|
||||
logging.error(response);
|
||||
logging.error(body);
|
||||
callback(null, null);
|
||||
callback(body || "Unknown error", null);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
12
test/test.js
12
test/test.js
@ -64,13 +64,13 @@ describe('Crafatar', function() {
|
||||
});
|
||||
it("should not exist (uuid)", function(done) {
|
||||
networking.get_skin_url("00000000000000000000000000000000", function(err, profile) {
|
||||
assert.strictEqual(err, 0);
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should not exist (username)", function(done) {
|
||||
networking.get_skin_url("Steve", function(err, profile) {
|
||||
assert.strictEqual(err, 0);
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -154,8 +154,14 @@ describe('Crafatar', function() {
|
||||
before(function() {
|
||||
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) {
|
||||
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);
|
||||
done();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user