From eb609b5c4274ad1c8e25fb341ba6ef3c9c792e69 Mon Sep 17 00:00:00 2001 From: Alexander Corn Date: Tue, 27 Feb 2018 01:40:59 -0500 Subject: [PATCH] Added some more explicit error handling if we try to do things while logged out --- components/profile.js | 76 +++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/components/profile.js b/components/profile.js index 9e35613..57bac14 100644 --- a/components/profile.js +++ b/components/profile.js @@ -21,7 +21,7 @@ SteamCommunity.prototype.setupProfile = function(callback) { if(!callback) { return; } - + if(err || response.statusCode != 200) { callback(err || new Error("HTTP error " + response.statusCode)); } else { @@ -37,82 +37,82 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if(callback) { callback(err || new Error("HTTP error " + response.statusCode)); } - + return; } - + var $ = Cheerio.load(body); var form = $('#editForm'); if(!form) { if(callback) { callback(new Error("Malformed response")); } - + return; } - + var values = {}; form.serializeArray().forEach(function(item) { values[item.name] = item.value; }); - + for(var i in settings) { if(!settings.hasOwnProperty(i)) { continue; } - + switch(i) { case 'name': values.personaName = settings[i]; break; - + case 'realName': values.real_name = settings[i]; break; - + case 'summary': values.summary = settings[i]; break; - + case 'country': values.country = settings[i]; break; - + case 'state': values.state = settings[i]; break; - + case 'city': values.city = settings[i]; break; - + case 'customURL': values.customURL = settings[i]; break; - + case 'background': // The assetid of our desired profile background values.profile_background = settings[i]; break; - + case 'featuredBadge': // Currently, game badges aren't supported values.favorite_badge_badgeid = settings[i]; break; - + case 'primaryGroup': if(typeof settings[i] === 'object' && settings[i].getSteamID64) { values.primary_group_steamid = settings[i].getSteamID64(); } else { values.primary_group_steamid = new SteamID(settings[i]).getSteamID64(); } - + break; - + // TODO: profile showcases } } - + self._myProfile("edit", values, function(err, response, body) { if (settings.customURL) { delete self._profileURL; @@ -122,10 +122,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if(callback) { callback(err || new Error("HTTP error " + response.statusCode)); } - + return; } - + // Check for an error var $ = Cheerio.load(body); var error = $('#errorText .formRowFields'); @@ -135,11 +135,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if(callback) { callback(new Error(error)); } - + return; } } - + if(callback) { callback(null); } @@ -154,58 +154,58 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) { if(callback) { callback(err || new Error("HTTP error " + response.statusCode)); } - + return; } - + var $ = Cheerio.load(body); var form = $('#editForm'); if(!form) { if(callback) { callback(new Error("Malformed response")); } - + return; } - + var values = {}; form.serializeArray().forEach(function(item) { values[item.name] = item.value; }); - + for(var i in settings) { if(!settings.hasOwnProperty(i)) { continue; } - + switch(i) { case 'profile': values.privacySetting = settings[i]; break; - + case 'comments': values.commentSetting = CommentPrivacyState[settings[i]]; break; - + case 'inventory': values.inventoryPrivacySetting = settings[i]; break; - + case 'inventoryGifts': values.inventoryGiftPrivacy = settings[i] ? 1 : 0; break; } } - + self._myProfile("edit/settings", values, function(err, response, body) { if(err || response.statusCode != 200) { if(callback) { callback(err || new Error("HTTP error " + response.statusCode)); } - + return; } - + if(callback) { callback(null); } @@ -219,6 +219,12 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) { format = null; } + // are we logged in? + if (!this.steamID) { + callback(new Error("Not Logged In")); + return; + } + var self = this; if(image instanceof Buffer) {