diff --git a/classes/CMarketItem.js b/classes/CMarketItem.js index 08c4baa..1fb5243 100644 --- a/classes/CMarketItem.js +++ b/classes/CMarketItem.js @@ -8,7 +8,8 @@ SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, cal } var self = this; this.httpRequest("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -107,7 +108,8 @@ CMarketItem.prototype.updatePriceForCommodity = function(currency, callback) { "uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english¤cy=" + currency + "&item_nameid=" + this.commodityID, "json": true }, function(err, response, body) { - if(self._community._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -153,7 +155,8 @@ CMarketItem.prototype.updatePriceForNonCommodity = function (currency, callback) "/render/?query=&start=0&count=10&country=US&language=english¤cy=" + currency, "json": true }, function(err, response, body) { - if (self._community._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/classes/CMarketSearchResult.js b/classes/CMarketSearchResult.js index 396d895..380b2fe 100644 --- a/classes/CMarketSearchResult.js +++ b/classes/CMarketSearchResult.js @@ -40,7 +40,8 @@ function performSearch(request, qs, results, callback) { }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/classes/CSteamGroup.js b/classes/CSteamGroup.js index c4e5241..1eeb1e7 100644 --- a/classes/CSteamGroup.js +++ b/classes/CSteamGroup.js @@ -13,11 +13,8 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) { var self = this; this.httpRequest("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { + if (err) { + callback(err); return; } diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 69f0cae..4b1efb6 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -13,11 +13,8 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) { var self = this; this.httpRequest("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { + if (err) { + callback(err); return; } diff --git a/components/chat.js b/components/chat.js index c36eb8d..f7ae06e 100644 --- a/components/chat.js +++ b/components/chat.js @@ -118,7 +118,8 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback) return; } - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/components/confirmations.js b/components/confirmations.js index fe7d329..261d365 100644 --- a/components/confirmations.js +++ b/components/confirmations.js @@ -153,7 +153,8 @@ function request(community, url, key, time, tag, params, json, callback) { "qs": params, "json": !!json }, function(err, response, body) { - if(community._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/components/groups.js b/components/groups.js index 13b990e..2ba201f 100644 --- a/components/groups.js +++ b/components/groups.js @@ -39,7 +39,8 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link var self = this; this.httpRequest(options, function(err, response, body) { - if (self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -84,16 +85,7 @@ SteamCommunity.prototype.joinGroup = function(gid, callback) { return; } - if(err || response.statusCode >= 400) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -112,16 +104,7 @@ SteamCommunity.prototype.leaveGroup = function(gid, callback) { return; } - if(err || response.statusCode >= 400) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }); }; @@ -139,12 +122,8 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback this.httpRequest({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/" }, function(err, response, body) { - - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { + if (err) { + callback(err); return; } @@ -196,15 +175,7 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -227,22 +198,14 @@ SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, co "languages[0][body]": content, "languages[0][updated]": 1 } - } + }; this.httpRequestPost(submitData, function(err, response, body) { if(!callback) { return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -262,15 +225,7 @@ SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback) return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -327,16 +282,7 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript return; } - if(err || response.statusCode >= 400) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -406,16 +352,7 @@ SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) { return; } - if(err || response.statusCode >= 400) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - if(self._checkCommunityError(body, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -431,11 +368,8 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { var self = this; this.httpRequest("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { + if (err) { + callback(err); return; } diff --git a/components/market.js b/components/market.js index 65f70de..c9b1849 100644 --- a/components/market.js +++ b/components/market.js @@ -4,9 +4,11 @@ var Cheerio = require('cheerio'); SteamCommunity.prototype.getMarketApps = function(callback) { var self = this; this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } + var $ = Cheerio.load(body); if ($('.market_search_game_button_group')) { apps = {}; diff --git a/components/twofactor.js b/components/twofactor.js index b134f40..e549101 100644 --- a/components/twofactor.js +++ b/components/twofactor.js @@ -28,7 +28,8 @@ SteamCommunity.prototype.enableTwoFactor = function(callback) { }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -77,7 +78,8 @@ SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, ca }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -127,7 +129,8 @@ SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) { }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/components/users.js b/components/users.js index a1d892d..72b7169 100644 --- a/components/users.js +++ b/components/users.js @@ -21,7 +21,8 @@ SteamCommunity.prototype.addFriend = function(userID, callback) { return; } - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -51,11 +52,7 @@ SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) { return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -76,11 +73,7 @@ SteamCommunity.prototype.removeFriend = function(userID, callback) { return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -101,11 +94,7 @@ SteamCommunity.prototype.blockCommunication = function(userID, callback) { return; } - if(self._checkHttpError(err, response, callback)) { - return; - } - - callback(null); + callback(err || null); }, "steamcommunity"); }; @@ -150,7 +139,8 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) { return; } - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -185,7 +175,8 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback) return; } - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -216,7 +207,8 @@ SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) { var self = this; this.httpRequest("https://steamcommunity.com/profiles/" + userID.getSteamID64() + "/inventory/", function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -257,7 +249,8 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } diff --git a/components/webapi.js b/components/webapi.js index 9d72b63..45cf997 100644 --- a/components/webapi.js +++ b/components/webapi.js @@ -6,7 +6,8 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) { "uri": "https://steamcommunity.com/dev/apikey", "followRedirect": false }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -28,7 +29,8 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) { "Submit": "Register" } }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -47,11 +49,8 @@ SteamCommunity.prototype.getWebApiOauthToken = function(callback) { // Pull an oauth token from the webchat UI this.httpRequest("https://steamcommunity.com/chat", function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(self._checkCommunityError(body, callback)) { + if (err) { + callback(err); return; } diff --git a/index.js b/index.js index 71a294f..faab44f 100644 --- a/index.js +++ b/index.js @@ -74,8 +74,9 @@ SteamCommunity.prototype.login = function(details, callback) { "json": true }, function(err, response, body) { // Remove the mobile cookies - if (self._checkHttpError(err, response, callback)) { + if (err) { deleteMobileCookies(); + callback(err); return; } @@ -110,7 +111,8 @@ SteamCommunity.prototype.login = function(details, callback) { }, function(err, response, body) { deleteMobileCookies(); - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -183,7 +185,8 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) { }, "json": true }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -247,16 +250,19 @@ SteamCommunity.prototype.parentalUnlock = function(pin, callback) { return; } - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } if(!body || typeof body.success !== 'boolean') { - return callback("Invalid response"); + callback("Invalid response"); + return; } if(!body.success) { - return callback("Incorrect PIN"); + callback("Incorrect PIN"); + return; } callback(); @@ -266,7 +272,8 @@ SteamCommunity.prototype.parentalUnlock = function(pin, callback) { SteamCommunity.prototype.getNotifications = function(callback) { var self = this; this.httpRequestGet("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { + if (err) { + callback(err); return; } @@ -305,12 +312,8 @@ SteamCommunity.prototype.resetItemNotifications = function(callback) { if(!callback) { return; } - - if(self._checkHttpError(err, response, callback)) { - return; - } - - callback(null); + + callback(err || null); }, "steamcommunity"); };