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