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"); };