Skip to content

Commit 855b627

Browse files
committed
handles exception in GetPurchaseStatus
1 parent f58a42a commit 855b627

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

ProjectPlugins/CodexClient/CodexAccess.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,25 @@ public CodexSpace Space()
152152
return mapper.Map(space);
153153
}
154154

155-
public StoragePurchase GetPurchaseStatus(string purchaseId)
155+
public StoragePurchase? GetPurchaseStatus(string purchaseId)
156156
{
157157
return CrashCheck(() =>
158158
{
159159
var endpoint = GetEndpoint();
160-
return Time.Retry(() =>
160+
try
161161
{
162-
var str = endpoint.HttpGetString($"storage/purchases/{purchaseId}");
163-
if (string.IsNullOrEmpty(str)) throw new Exception("Empty response.");
164-
return JsonConvert.DeserializeObject<StoragePurchase>(str)!;
165-
}, nameof(GetPurchaseStatus));
162+
return Time.Retry(() =>
163+
{
164+
var str = endpoint.HttpGetString($"storage/purchases/{purchaseId}");
165+
if (string.IsNullOrEmpty(str)) throw new Exception("Empty response.");
166+
return JsonConvert.DeserializeObject<StoragePurchase>(str)!;
167+
}, nameof(GetPurchaseStatus));
168+
}
169+
catch (Exception exc)
170+
{
171+
log.Error($"Failed to fetch purchase information for id: '{purchaseId}'. Exception: {exc.Message}");
172+
return null;
173+
}
166174
});
167175

168176
// TODO: current getpurchase api does not line up with its openapi spec.

ProjectPlugins/CodexClient/CodexNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public partial interface ICodexNode : IHasEthAddress, IHasMetricsScrapeTarget
3030
IMarketplaceAccess Marketplace { get; }
3131
ITransferSpeeds TransferSpeeds { get; }
3232
EthAccount EthAccount { get; }
33-
StoragePurchase GetPurchaseStatus(string purchaseId);
33+
StoragePurchase? GetPurchaseStatus(string purchaseId);
3434

3535
Address GetDiscoveryEndpoint();
3636
Address GetApiEndpoint();
@@ -86,7 +86,7 @@ public void Initialize()
8686
public DebugInfoVersion Version { get; private set; }
8787
public ITransferSpeeds TransferSpeeds { get => transferSpeeds; }
8888

89-
public StoragePurchase GetPurchaseStatus(string purchaseId)
89+
public StoragePurchase? GetPurchaseStatus(string purchaseId)
9090
{
9191
return codexAccess.GetPurchaseStatus(purchaseId);
9292
}

0 commit comments

Comments
 (0)