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) {
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) {