Fixed getUserInventoryContexts not properly returning errors for private inventory/profile

Closes #305
This commit is contained in:
Alex Corn 2023-06-27 00:53:55 -04:00
parent 29e18806cc
commit f69519f547
No known key found for this signature in database
GPG Key ID: E51989A3E7A27FDF

View File

@ -385,18 +385,7 @@ SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
var match = body.match(/var g_rgAppContextData = ([^\n]+);\r?\n/);
if (!match) {
var errorMessage = "Malformed response";
if(body.match(/0 items in their inventory\./)){
callback(null, {});
return;
}else if(body.match(/inventory is currently private\./)){
errorMessage = "Private inventory";
}else if(body.match(/profile\_private\_info/)){
errorMessage = "Private profile";
}
callback(new Error(errorMessage));
callback(new Error('Malformed response'));
return;
}
@ -408,6 +397,21 @@ SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
return;
}
if (Object.keys(data).length == 0) {
if (body.match(/inventory is currently private\./)) {
callback(new Error('Private inventory'));
return;
}
if (body.match(/profile_private_info/)) {
callback(new Error('Private profile'));
return;
}
// If they truly have no items in their inventory, Steam will send g_rgAppContextData as [] instead of {}.
data = {};
}
callback(null, data);
}, "steamcommunity");
};