Skip to content

Commit

Permalink
Merge pull request #46 from Sadzurami/feat/better-inventory-errors-ha…
Browse files Browse the repository at this point in the history
…ndling

feat/better-inventory-errors-handling
  • Loading branch information
yakikotori authored Sep 27, 2023
2 parents eff7a58 + 233970a commit 45f6423
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions BotLooter/Looting/LootClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public async Task<LootResult> TryLoot(TradeOfferUrl tradeOfferUrl, Configuration
var contextId = split[1];

var inventoryResponse = await _steamWeb.LoadInventory(inventoryId, contextId);
if (inventoryResponse is not {} inventoryData)

if (inventoryResponse is null || inventoryResponse is not {} inventoryData)
{
return (null, $"Не смог получить инвентарь {inventory}.");
}
Expand Down
2 changes: 1 addition & 1 deletion BotLooter/Steam/Contracts/Responses/InventoryResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class InventoryResponse
public List<Description>? Descriptions { get; set; }

[JsonProperty("total_inventory_count")]
public int TotalInventoryCount { get; set; }
public int? TotalInventoryCount { get; set; }

[JsonProperty("last_assetid")]
public string? LastAssetId { get; set; }
Expand Down
9 changes: 7 additions & 2 deletions BotLooter/Steam/SteamWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SteamWeb(SteamUserSession userSession)
}

// bad response
if (res.Data.TotalInventoryCount != 0 && res.Data.Assets is not null && res.Data.Descriptions is null)
if (res.Data.TotalInventoryCount is null || res.Data.TotalInventoryCount > 0 && (res.Data.Assets is null || res.Data.Descriptions is null))
{
return true;
}
Expand Down Expand Up @@ -105,8 +105,13 @@ public SteamWeb(SteamUserSession userSession)

var response = await _getInventoryPolicy.ExecuteAsync(async () => await _userSession.WebRequest<InventoryResponse?>(request));

if (response.StatusCode != HttpStatusCode.OK || response.Data is null || response.Data.Success != 1)
{
return null;
}

// bad response
if (response.Data is not null && response.Data.Assets is not null && response.Data.Descriptions is null)
if (response.Data.TotalInventoryCount is null || response.Data.TotalInventoryCount > 0 && (response.Data.Assets is null || response.Data.Descriptions is null))
{
return null;
}
Expand Down

0 comments on commit 45f6423

Please sign in to comment.