From 9ae9a17e71739082b9c4c39e2a83488ae88adb7b Mon Sep 17 00:00:00 2001 From: Sik Date: Mon, 7 Oct 2024 11:33:32 +0200 Subject: [PATCH] fix: handled responses with null content --- Web/API/Request.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Web/API/Request.cs b/Web/API/Request.cs index f9aa5cc..05ac2f7 100644 --- a/Web/API/Request.cs +++ b/Web/API/Request.cs @@ -391,9 +391,19 @@ private async Task> Process(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(); string ContentResponse = await response.Content?.ReadAsStringAsync(); switch (true)