Fixed getWebApiKey not failing if not logged in

This commit is contained in:
Alexander Corn 2015-09-02 17:19:12 -04:00
parent 0116842deb
commit c2ad457e87

View File

@ -149,8 +149,11 @@ function generateSessionID() {
SteamCommunity.prototype.getWebApiKey = function(domain, callback) { SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this; var self = this;
this.request("https://steamcommunity.com/dev/apikey", function(err, response, body) { this.request({
if(self._checkHttpError(err, response, callback)) { "uri": "https://steamcommunity.com/dev/apikey",
"followRedirect": false
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback, true)) {
return; return;
} }
@ -172,8 +175,8 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
"Submit": "Register" "Submit": "Register"
} }
}, function(err, response, body) { }, function(err, response, body) {
if(err || response.statusCode >= 400) { if(self._checkHttpError(err, response, callback)) {
return callback(err.message || "HTTP error " + response.statusCode); return;
} }
self.getWebApiKey(domain, callback); self.getWebApiKey(domain, callback);
@ -302,13 +305,13 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
}); });
}; };
SteamCommunity.prototype._checkHttpError = function(err, response, callback) { SteamCommunity.prototype._checkHttpError = function(err, response, callback, redirectIsFailure) {
if(err) { if(err) {
callback(err); callback(err);
return true; return true;
} }
if(response.statusCode != 200) { if(response.statusCode >= (redirectIsFailure ? 300 : 400)) {
var error = new Error("HTTP error " + response.statusCode); var error = new Error("HTTP error " + response.statusCode);
error.code = response.statusCode; error.code = response.statusCode;
callback(error); callback(error);