Skip to content

Commit

Permalink
fix: handled responses with null content
Browse files Browse the repository at this point in the history
  • Loading branch information
sikelio committed Oct 7, 2024
1 parent 2f77cac commit 9ae9a17
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Web/API/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,19 @@ private async Task<Result<T>> Process<T>(HttpRequestMessage request)
response = await _httpClient.SendAsync(request);
result.StatusCode = (int)response.StatusCode;

if (
response.Content == null ||
string.IsNullOrEmpty(await response.Content.ReadAsStringAsync())
)
{
result.Value = default;

return result;
}

if (response.IsSuccessStatusCode)
{
string MediaType = response.Content?.Headers?.ContentType?.MediaType.ToLower();
string? MediaType = response.Content?.Headers?.ContentType?.MediaType.ToLower();

Check warning on line 406 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 406 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
string ContentResponse = await response.Content?.ReadAsStringAsync();

Check warning on line 407 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 407 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

switch (true)
Expand Down

0 comments on commit 9ae9a17

Please sign in to comment.