Added some more explicit error handling if we try to do things while logged out

This commit is contained in:
Alexander Corn 2018-02-27 01:40:59 -05:00
parent 238a36de0f
commit eb609b5c42

View File

@ -21,7 +21,7 @@ SteamCommunity.prototype.setupProfile = function(callback) {
if(!callback) { if(!callback) {
return; return;
} }
if(err || response.statusCode != 200) { if(err || response.statusCode != 200) {
callback(err || new Error("HTTP error " + response.statusCode)); callback(err || new Error("HTTP error " + response.statusCode));
} else { } else {
@ -37,82 +37,82 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
if(callback) { if(callback) {
callback(err || new Error("HTTP error " + response.statusCode)); callback(err || new Error("HTTP error " + response.statusCode));
} }
return; return;
} }
var $ = Cheerio.load(body); var $ = Cheerio.load(body);
var form = $('#editForm'); var form = $('#editForm');
if(!form) { if(!form) {
if(callback) { if(callback) {
callback(new Error("Malformed response")); callback(new Error("Malformed response"));
} }
return; return;
} }
var values = {}; var values = {};
form.serializeArray().forEach(function(item) { form.serializeArray().forEach(function(item) {
values[item.name] = item.value; values[item.name] = item.value;
}); });
for(var i in settings) { for(var i in settings) {
if(!settings.hasOwnProperty(i)) { if(!settings.hasOwnProperty(i)) {
continue; continue;
} }
switch(i) { switch(i) {
case 'name': case 'name':
values.personaName = settings[i]; values.personaName = settings[i];
break; break;
case 'realName': case 'realName':
values.real_name = settings[i]; values.real_name = settings[i];
break; break;
case 'summary': case 'summary':
values.summary = settings[i]; values.summary = settings[i];
break; break;
case 'country': case 'country':
values.country = settings[i]; values.country = settings[i];
break; break;
case 'state': case 'state':
values.state = settings[i]; values.state = settings[i];
break; break;
case 'city': case 'city':
values.city = settings[i]; values.city = settings[i];
break; break;
case 'customURL': case 'customURL':
values.customURL = settings[i]; values.customURL = settings[i];
break; break;
case 'background': case 'background':
// The assetid of our desired profile background // The assetid of our desired profile background
values.profile_background = settings[i]; values.profile_background = settings[i];
break; break;
case 'featuredBadge': case 'featuredBadge':
// Currently, game badges aren't supported // Currently, game badges aren't supported
values.favorite_badge_badgeid = settings[i]; values.favorite_badge_badgeid = settings[i];
break; break;
case 'primaryGroup': case 'primaryGroup':
if(typeof settings[i] === 'object' && settings[i].getSteamID64) { if(typeof settings[i] === 'object' && settings[i].getSteamID64) {
values.primary_group_steamid = settings[i].getSteamID64(); values.primary_group_steamid = settings[i].getSteamID64();
} else { } else {
values.primary_group_steamid = new SteamID(settings[i]).getSteamID64(); values.primary_group_steamid = new SteamID(settings[i]).getSteamID64();
} }
break; break;
// TODO: profile showcases // TODO: profile showcases
} }
} }
self._myProfile("edit", values, function(err, response, body) { self._myProfile("edit", values, function(err, response, body) {
if (settings.customURL) { if (settings.customURL) {
delete self._profileURL; delete self._profileURL;
@ -122,10 +122,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
if(callback) { if(callback) {
callback(err || new Error("HTTP error " + response.statusCode)); callback(err || new Error("HTTP error " + response.statusCode));
} }
return; return;
} }
// Check for an error // Check for an error
var $ = Cheerio.load(body); var $ = Cheerio.load(body);
var error = $('#errorText .formRowFields'); var error = $('#errorText .formRowFields');
@ -135,11 +135,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
if(callback) { if(callback) {
callback(new Error(error)); callback(new Error(error));
} }
return; return;
} }
} }
if(callback) { if(callback) {
callback(null); callback(null);
} }
@ -154,58 +154,58 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
if(callback) { if(callback) {
callback(err || new Error("HTTP error " + response.statusCode)); callback(err || new Error("HTTP error " + response.statusCode));
} }
return; return;
} }
var $ = Cheerio.load(body); var $ = Cheerio.load(body);
var form = $('#editForm'); var form = $('#editForm');
if(!form) { if(!form) {
if(callback) { if(callback) {
callback(new Error("Malformed response")); callback(new Error("Malformed response"));
} }
return; return;
} }
var values = {}; var values = {};
form.serializeArray().forEach(function(item) { form.serializeArray().forEach(function(item) {
values[item.name] = item.value; values[item.name] = item.value;
}); });
for(var i in settings) { for(var i in settings) {
if(!settings.hasOwnProperty(i)) { if(!settings.hasOwnProperty(i)) {
continue; continue;
} }
switch(i) { switch(i) {
case 'profile': case 'profile':
values.privacySetting = settings[i]; values.privacySetting = settings[i];
break; break;
case 'comments': case 'comments':
values.commentSetting = CommentPrivacyState[settings[i]]; values.commentSetting = CommentPrivacyState[settings[i]];
break; break;
case 'inventory': case 'inventory':
values.inventoryPrivacySetting = settings[i]; values.inventoryPrivacySetting = settings[i];
break; break;
case 'inventoryGifts': case 'inventoryGifts':
values.inventoryGiftPrivacy = settings[i] ? 1 : 0; values.inventoryGiftPrivacy = settings[i] ? 1 : 0;
break; break;
} }
} }
self._myProfile("edit/settings", values, function(err, response, body) { self._myProfile("edit/settings", values, function(err, response, body) {
if(err || response.statusCode != 200) { if(err || response.statusCode != 200) {
if(callback) { if(callback) {
callback(err || new Error("HTTP error " + response.statusCode)); callback(err || new Error("HTTP error " + response.statusCode));
} }
return; return;
} }
if(callback) { if(callback) {
callback(null); callback(null);
} }
@ -219,6 +219,12 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
format = null; format = null;
} }
// are we logged in?
if (!this.steamID) {
callback(new Error("Not Logged In"));
return;
}
var self = this; var self = this;
if(image instanceof Buffer) { if(image instanceof Buffer) {