From bb23cb66298698259286998d844ffb2f0f95e2f0 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 20 Apr 2026 10:19:40 +0200 Subject: [PATCH] Refactor error handling to use ApiClientHelper Replaced the private ReadErrorAsync method in LayoutApiClient with calls to ApiClientHelper.ReadErrorAsync, centralizing error handling logic for improved consistency and reuse. --- DbFirst.BlazorWebApp/Services/LayoutApiClient.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/DbFirst.BlazorWebApp/Services/LayoutApiClient.cs b/DbFirst.BlazorWebApp/Services/LayoutApiClient.cs index ad77fe0..0a863e8 100644 --- a/DbFirst.BlazorWebApp/Services/LayoutApiClient.cs +++ b/DbFirst.BlazorWebApp/Services/LayoutApiClient.cs @@ -31,7 +31,7 @@ public class LayoutApiClient var response = await _httpClient.PostAsJsonAsync(Endpoint, dto); if (!response.IsSuccessStatusCode) { - var detail = await ReadErrorAsync(response); + var detail = await ApiClientHelper.ReadErrorAsync(response); throw new InvalidOperationException(detail); } @@ -39,17 +39,6 @@ public class LayoutApiClient return payload ?? dto; } - private static async Task ReadErrorAsync(HttpResponseMessage response) - { - var body = await response.Content.ReadAsStringAsync(); - if (!string.IsNullOrWhiteSpace(body)) - { - return body; - } - - return $"{(int)response.StatusCode} {response.ReasonPhrase}".Trim(); - } - public async Task DeleteAsync(string layoutType, string layoutKey, string userName) { var url = $"{Endpoint}?layoutType={Uri.EscapeDataString(layoutType)}&layoutKey={Uri.EscapeDataString(layoutKey)}&userName={Uri.EscapeDataString(userName)}";