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.
This commit is contained in:
@@ -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<string> 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)}";
|
||||
|
||||
Reference in New Issue
Block a user