Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outgoing bookmark #53

Merged
merged 7 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Include content of HTTP errors
michaellperry committed Nov 1, 2023

Verified

This commit was signed with the committer’s verified signature.
MauriceVanVeen Maurice van Veen
commit 3061ba7f1738d57b17c4e90367aae4ccdc52162f
23 changes: 21 additions & 2 deletions Jinaga/Http/HttpConnection.cs
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ private async Task<T> WithHttpClient<T>(
using var retryRequest = createRequest();
setRequestHeaders(retryRequest.Headers);
using var retryResponse = await httpClient.SendAsync(retryRequest).ConfigureAwait(false);
retryResponse.EnsureSuccessStatusCode();
await CheckForError(response).ConfigureAwait(false);
var retryResult = await processResponse(retryResponse).ConfigureAwait(false);
return retryResult;
}
@@ -114,7 +114,7 @@ private async Task<T> WithHttpClient<T>(
}
else
{
response.EnsureSuccessStatusCode();
await CheckForError(response).ConfigureAwait(false);
var result = await processResponse(response).ConfigureAwait(false);
return result;
}
@@ -125,5 +125,24 @@ private async Task<T> WithHttpClient<T>(
throw;
}
}

private async Task CheckForError(HttpResponseMessage response)
{
if (!response.IsSuccessStatusCode)
{
string body = string.Empty;
try
{
// Read the content of the error from the response.
body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
catch
{
// Fall back on the default behavior.
response.EnsureSuccessStatusCode();
}
throw new HttpRequestException($"Error {response.StatusCode}: {body}");
}
}
}
}