From f69519f547e4d545d9a3e030dea67f2a1148eedc Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Tue, 27 Jun 2023 00:53:55 -0400 Subject: [PATCH] Fixed getUserInventoryContexts not properly returning errors for private inventory/profile Closes #305 --- components/users.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/components/users.js b/components/users.js index c0e9a22..df8a90f 100644 --- a/components/users.js +++ b/components/users.js @@ -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"); };