Improve ThrowRequestExceptionFromContentAsync
MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClientBase.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClientBase.cs
@@ -539,7 +539,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
aliceClient?.Dispose();
return;
}
- catch (HttpRequestException ex) when (ex.Message.Contains("No such running round in InputRegistration.", StringComparison.InvariantCultureIgnoreCase))
+ catch (HttpRequestException ex) when (ex.Message.Contains("No such running round in InputRegistration", StringComparison.InvariantCultureIgnoreCase))
{
Logger.LogInfo("Client tried to register a round that is not in InputRegistration anymore. Trying again later.");
aliceClient?.Dispose();

MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -87,19 +87,17 @@ namespace System.Net.Http
public static async Task ThrowRequestExceptionFromContentAsync(this HttpResponseMessage me)
{
- string error = null;
- try
+ var errorMessage = "";
+ if (me?.Content is { })
{
- if (me.Content.Headers?.ContentType?.MediaType != "text/html")
+ var contentString = await me.Content.ReadAsStringAsync().ConfigureAwait(false);
+
+ if (!string.IsNullOrWhiteSpace(contentString) && contentString.Length <= 1000)
{
- error = await me.Content.ReadAsJsonAsync<string>().ConfigureAwait(false);
- }
+ errorMessage = $"\n{contentString}";
}
- catch (Exception ex)
- {
- Logger.LogDebug(ex);
}
- string errorMessage = error is null ? string.Empty : $"\n{error}";
+
throw new HttpRequestException($"{me.StatusCode.ToReasonString()}{errorMessage}");
}
}

Improve ThrowRequestExceptionFromContentAsync