refactor: cambio las respuestas de error para no culpar al usuario al fallar la deserializacion sino como una ApiException

This commit is contained in:
javiermengual 2025-12-30 19:13:26 +01:00
parent 572547b356
commit 198fccd5bc
1 changed files with 7 additions and 5 deletions

View File

@ -48,7 +48,7 @@ public class DolibarrApiClient
await HandleErrorsAsync(response, endpoint); await HandleErrorsAsync(response, endpoint);
return await response.Content.ReadFromJsonAsync<T>() return await response.Content.ReadFromJsonAsync<T>()
?? throw new BadRequestException("Failed to deserialize response"); ?? throw new ApiException($"Failed to deserialize response from Dolibarr for endpoint '{endpoint}'");
} }
private async Task<List<T>> GetListAsync<T>(string endpoint) where T : class private async Task<List<T>> GetListAsync<T>(string endpoint) where T : class
@ -56,7 +56,9 @@ public class DolibarrApiClient
var response = await _httpClient.GetAsync(endpoint); var response = await _httpClient.GetAsync(endpoint);
await HandleErrorsAsync(response, endpoint); await HandleErrorsAsync(response, endpoint);
return await response.Content.ReadFromJsonAsync<List<T>>() ?? new List<T>(); return await response.Content.ReadFromJsonAsync<List<T>>()
?? throw new ApiException(
$"Failed to deserialize list response from Dolibarr for endpoint '{endpoint}'");
} }
private async Task HandleErrorsAsync(HttpResponseMessage response, string endpoint) private async Task HandleErrorsAsync(HttpResponseMessage response, string endpoint)