Created method for throwing request exceptions
Moved repeated logic to extension method.
Changed PostConfirmationAsync control flow to be in line with other
methods.
MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -81,5 +81,12 @@ namespace System.Net.Http
return startLine + headers + CRLF + messageBody;
}
+
+ public async static Task ThrowRequestExceptionAsync<T>(this HttpResponseMessage me)
+ {
+ T error = await me.Content.ReadAsJsonAsync<T>();
+ string errorMessage = error == null ? string.Empty : $"\n{error}";
+ throw new HttpRequestException($"{me.StatusCode.ToReasonString()}{errorMessage}");
+ }
}
}

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/AliceClient.cs
@@ -36,9 +36,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
var inputsResponse = await response.Content.ReadAsJsonAsync<InputsResponse>();
@@ -80,17 +78,15 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
return null;
}
- if (response.StatusCode == HttpStatusCode.OK)
+ if (response.StatusCode != HttpStatusCode.OK)
{
+ await response.ThrowRequestExceptionAsync<string>();
+ }
+
string roundHash = await response.Content.ReadAsJsonAsync<string>();
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Confirmed connection. Acquired roundHash: {roundHash}.");
return roundHash;
}
-
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
- }
}
/// <returns>null or roundHash</returns>
@@ -100,9 +96,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (!response.IsSuccessStatusCode)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Unconfirmed connection.");
}
@@ -114,9 +108,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
var coinjoinHex = await response.Content.ReadAsJsonAsync<string>();
@@ -137,9 +129,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.NoContent)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
Logger.LogInfo<AliceClient>($"Round ({RoundId}), Alice ({UniqueId}): Posted {signatures.Count} signatures.");
}

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/BobClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/BobClient.cs
@@ -23,9 +23,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.NoContent)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
}
}

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/SatoshiClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/SatoshiClient.cs
@@ -25,9 +25,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
var states = await response.Content.ReadAsJsonAsync<IEnumerable<CcjRunningRoundState>>();

MODIFY
WalletWasabi/WebClients/ChaumianCoinJoin/WasabiClient.cs
WalletWasabi/WebClients/ChaumianCoinJoin/WasabiClient.cs
@@ -36,9 +36,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
}
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
using (HttpContent content = response.Content)
@@ -57,9 +55,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
using (HttpContent content = response.Content)
@@ -77,9 +73,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
}
}
@@ -104,9 +98,7 @@ namespace WalletWasabi.WebClients.ChaumianCoinJoin
{
if (response.StatusCode != HttpStatusCode.OK)
{
- string error = await response.Content.ReadAsJsonAsync<string>();
- var errorMessage = error == null ? string.Empty : $"\n{error}";
- throw new HttpRequestException($"{response.StatusCode.ToReasonString()}{errorMessage}");
+ await response.ThrowRequestExceptionAsync<string>();
}
using (HttpContent content = response.Content)

Created method for throwing request exceptions

Moved repeated logic to extension method.
Changed PostConfirmationAsync control flow to be in line with other
methods.