handles exception in GetPurchaseStatus

This commit is contained in:
ThatBen 2025-03-03 16:27:10 +01:00
parent f58a42a1ca
commit 855b627823
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
2 changed files with 16 additions and 8 deletions

View File

@ -152,17 +152,25 @@ namespace CodexClient
return mapper.Map(space);
}
public StoragePurchase GetPurchaseStatus(string purchaseId)
public StoragePurchase? GetPurchaseStatus(string purchaseId)
{
return CrashCheck(() =>
{
var endpoint = GetEndpoint();
return Time.Retry(() =>
try
{
var str = endpoint.HttpGetString($"storage/purchases/{purchaseId}");
if (string.IsNullOrEmpty(str)) throw new Exception("Empty response.");
return JsonConvert.DeserializeObject<StoragePurchase>(str)!;
}, nameof(GetPurchaseStatus));
return Time.Retry(() =>
{
var str = endpoint.HttpGetString($"storage/purchases/{purchaseId}");
if (string.IsNullOrEmpty(str)) throw new Exception("Empty response.");
return JsonConvert.DeserializeObject<StoragePurchase>(str)!;
}, nameof(GetPurchaseStatus));
}
catch (Exception exc)
{
log.Error($"Failed to fetch purchase information for id: '{purchaseId}'. Exception: {exc.Message}");
return null;
}
});
// TODO: current getpurchase api does not line up with its openapi spec.

View File

@ -30,7 +30,7 @@ namespace CodexClient
IMarketplaceAccess Marketplace { get; }
ITransferSpeeds TransferSpeeds { get; }
EthAccount EthAccount { get; }
StoragePurchase GetPurchaseStatus(string purchaseId);
StoragePurchase? GetPurchaseStatus(string purchaseId);
Address GetDiscoveryEndpoint();
Address GetApiEndpoint();
@ -86,7 +86,7 @@ namespace CodexClient
public DebugInfoVersion Version { get; private set; }
public ITransferSpeeds TransferSpeeds { get => transferSpeeds; }
public StoragePurchase GetPurchaseStatus(string purchaseId)
public StoragePurchase? GetPurchaseStatus(string purchaseId)
{
return codexAccess.GetPurchaseStatus(purchaseId);
}