mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
return HTTPERROR on 429 or 5xx, fixes #151
otherwise 429 or 5xx would be overwriting cached value with null for $config minutes
This commit is contained in:
parent
d307aec221
commit
fb0c70d648
@ -75,7 +75,7 @@ exp.info = function(callback) {
|
|||||||
// these 60 seconds match the duration of Mojang's rate limit ban
|
// these 60 seconds match the duration of Mojang's rate limit ban
|
||||||
// callback: error
|
// callback: error
|
||||||
exp.update_timestamp = function(rid, userId, temp, callback) {
|
exp.update_timestamp = function(rid, userId, temp, callback) {
|
||||||
logging.debug(rid, "updating cache timestamp");
|
logging.debug(rid, "updating cache timestamp (" + temp + ")");
|
||||||
var sub = temp ? config.caching.local - 60 : 0;
|
var sub = temp ? config.caching.local - 60 : 0;
|
||||||
var time = Date.now() - sub;
|
var time = Date.now() - sub;
|
||||||
// store userId in lower case if not null
|
// store userId in lower case if not null
|
||||||
|
|||||||
@ -77,6 +77,11 @@ exp.get_from_options = function(rid, url, options, callback) {
|
|||||||
var logfunc = code && code < 405 ? logging.debug : logging.warn;
|
var logfunc = code && code < 405 ? logging.debug : logging.warn;
|
||||||
logfunc(rid, url, code || error && error.code, http_code[code]);
|
logfunc(rid, url, code || error && error.code, http_code[code]);
|
||||||
|
|
||||||
|
// not necessarily used
|
||||||
|
var e = new Error(code);
|
||||||
|
e.name = "HTTP";
|
||||||
|
e.code = "HTTPERROR";
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 200:
|
case 200:
|
||||||
case 301:
|
case 301:
|
||||||
@ -85,13 +90,17 @@ exp.get_from_options = function(rid, url, options, callback) {
|
|||||||
case 308: // never seen, but mojang might use it in future
|
case 308: // never seen, but mojang might use it in future
|
||||||
// these are okay
|
// these are okay
|
||||||
break;
|
break;
|
||||||
|
case 204: // no content, used like 404 by mojang. making sure it really has no content
|
||||||
case 404:
|
case 404:
|
||||||
case 204:
|
// can be cached as null
|
||||||
|
body = null;
|
||||||
|
break;
|
||||||
case 429: // this shouldn't usually happen, but occasionally does
|
case 429: // this shouldn't usually happen, but occasionally does
|
||||||
case 500:
|
case 500:
|
||||||
case 503:
|
case 503:
|
||||||
case 504:
|
case 504:
|
||||||
// we don't want to cache this
|
// we don't want to cache this
|
||||||
|
error = error || e;
|
||||||
body = null;
|
body = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -99,6 +108,7 @@ exp.get_from_options = function(rid, url, options, callback) {
|
|||||||
// Probably 500 or the likes
|
// Probably 500 or the likes
|
||||||
logging.error(rid, "Unexpected response:", code, body);
|
logging.error(rid, "Unexpected response:", code, body);
|
||||||
}
|
}
|
||||||
|
error = error || e;
|
||||||
body = null;
|
body = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ var human_status = {
|
|||||||
|
|
||||||
|
|
||||||
// print these, but without stacktrace
|
// print these, but without stacktrace
|
||||||
var silent_errors = ["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "EHOSTUNREACH", "ECONNREFUSED"];
|
var silent_errors = ["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "EHOSTUNREACH", "ECONNREFUSED", "HTTPERROR"];
|
||||||
|
|
||||||
// handles HTTP responses
|
// handles HTTP responses
|
||||||
// +request+ a http.IncomingMessage
|
// +request+ a http.IncomingMessage
|
||||||
|
|||||||
@ -1020,7 +1020,7 @@ describe("Crafatar", function() {
|
|||||||
it("uuid should be rate limited", function(done) {
|
it("uuid should be rate limited", function(done) {
|
||||||
networking.get_profile(rid, id, function() {
|
networking.get_profile(rid, id, function() {
|
||||||
networking.get_profile(rid, id, function(err, profile) {
|
networking.get_profile(rid, id, function(err, profile) {
|
||||||
assert.ifError(err);
|
assert.strictEqual(err.toString(), "HTTP: 429");
|
||||||
assert.strictEqual(profile, null);
|
assert.strictEqual(profile, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user