mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Retry inventory requests on error 29
This commit is contained in:
@@ -26,9 +26,11 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using ArchiSteamFarm.Core;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using ArchiSteamFarm.Steam.Integration;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SteamKit2;
|
||||
|
||||
namespace ArchiSteamFarm.Steam.Data;
|
||||
|
||||
@@ -40,15 +42,28 @@ internal sealed class InventoryResponse : OptionalResultResponse {
|
||||
[JsonProperty("descriptions", Required = Required.DisallowNull)]
|
||||
internal readonly ImmutableHashSet<Description> Descriptions = ImmutableHashSet<Description>.Empty;
|
||||
|
||||
[JsonProperty("error", Required = Required.DisallowNull)]
|
||||
internal readonly string Error = "";
|
||||
|
||||
[JsonProperty("total_inventory_count", Required = Required.DisallowNull)]
|
||||
internal readonly uint TotalInventoryCount;
|
||||
|
||||
internal EResult? ErrorCode { get; private set; }
|
||||
internal string? ErrorText { get; private set; }
|
||||
internal ulong LastAssetID { get; private set; }
|
||||
internal bool MoreItems { get; private set; }
|
||||
|
||||
[JsonProperty("error", Required = Required.DisallowNull)]
|
||||
private string Error {
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
ASF.ArchiLogger.LogNullError(value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorCode = SteamUtilities.InterpretError(value);
|
||||
ErrorText = value;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("last_assetid", Required = Required.DisallowNull)]
|
||||
private string LastAssetIDText {
|
||||
set {
|
||||
|
||||
@@ -188,16 +188,25 @@ public sealed class ArchiWebHandler : IDisposable {
|
||||
}
|
||||
|
||||
if (response.StatusCode.IsServerErrorCode()) {
|
||||
if (string.IsNullOrEmpty(response.Content?.Error)) {
|
||||
if (string.IsNullOrEmpty(response.Content?.ErrorText)) {
|
||||
// This is a generic server error without a reason, try again
|
||||
response = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Interpret the reason and see if we should try again
|
||||
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
|
||||
switch (response.Content!.ErrorCode) {
|
||||
case EResult.DuplicateRequest:
|
||||
response = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// This is actually client error with a reason, so it doesn't make sense to retry
|
||||
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
|
||||
throw new HttpRequestException(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content!.Error), null, response.StatusCode);
|
||||
throw new HttpRequestException(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content!.ErrorText), null, response.StatusCode);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -218,7 +227,7 @@ public sealed class ArchiWebHandler : IDisposable {
|
||||
}
|
||||
|
||||
if (response.Content.Result is not EResult.OK) {
|
||||
throw new HttpRequestException(!string.IsNullOrEmpty(response.Content.Error) ? string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content.Error) : response.Content.Result.HasValue ? string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content.Result) : Strings.WarningFailed);
|
||||
throw new HttpRequestException(!string.IsNullOrEmpty(response.Content.ErrorText) ? string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content.ErrorText) : response.Content.Result.HasValue ? string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.Content.Result) : Strings.WarningFailed);
|
||||
}
|
||||
|
||||
if (response.Content.TotalInventoryCount == 0) {
|
||||
|
||||
@@ -21,12 +21,52 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using ArchiSteamFarm.Core;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using SteamKit2;
|
||||
|
||||
namespace ArchiSteamFarm.Steam.Integration;
|
||||
|
||||
internal static class SteamUtilities {
|
||||
internal static EResult? InterpretError(string errorText) {
|
||||
if (string.IsNullOrEmpty(errorText)) {
|
||||
throw new ArgumentNullException(nameof(errorText));
|
||||
}
|
||||
|
||||
int startIndex = errorText.LastIndexOf('(');
|
||||
|
||||
if (startIndex < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
startIndex++;
|
||||
|
||||
int endIndex = errorText.IndexOf(')', startIndex + 1);
|
||||
|
||||
if (endIndex < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
string errorCodeText = errorText[startIndex..endIndex];
|
||||
|
||||
if (!byte.TryParse(errorCodeText, out byte errorCode)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(errorCodeText), errorCodeText));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
EResult result = (EResult) errorCode;
|
||||
|
||||
if (!Enum.IsDefined(result)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(EResult), result));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Dictionary<uint, string>? ParseItems(this SteamApps.PurchaseResponseCallback callback) {
|
||||
ArgumentNullException.ThrowIfNull(callback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user