diff --git a/DoliMiddlewareApi/Services/DolibarrApiClient.cs b/DoliMiddlewareApi/Services/DolibarrApiClient.cs index 3a99680..0525875 100644 --- a/DoliMiddlewareApi/Services/DolibarrApiClient.cs +++ b/DoliMiddlewareApi/Services/DolibarrApiClient.cs @@ -23,7 +23,7 @@ public class DolibarrApiClient var data = await GetAsync($"invoices/{id}"); return InvoiceMapper.MapToInvoiceDetailDto(data); } - + public async Task> GetInvoicesAsync( int limit = 50, int page = 1, @@ -36,11 +36,11 @@ public class DolibarrApiClient { endpoint += $"&status={status}"; } - + var dataList = await GetListAsync(endpoint); return dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList(); } - + // ===== MÉTODOS GENÉRICOS ===== private async Task GetAsync(string endpoint) where T : class { @@ -48,7 +48,7 @@ public class DolibarrApiClient await HandleErrorsAsync(response, endpoint); return await response.Content.ReadFromJsonAsync() - ?? throw new BadRequestException("Failed to deserialize response"); + ?? throw new ApiException($"Failed to deserialize response from Dolibarr for endpoint '{endpoint}'"); } private async Task> GetListAsync(string endpoint) where T : class @@ -56,7 +56,9 @@ public class DolibarrApiClient var response = await _httpClient.GetAsync(endpoint); await HandleErrorsAsync(response, endpoint); - return await response.Content.ReadFromJsonAsync>() ?? new List(); + return await response.Content.ReadFromJsonAsync>() + ?? throw new ApiException( + $"Failed to deserialize list response from Dolibarr for endpoint '{endpoint}'"); } private async Task HandleErrorsAsync(HttpResponseMessage response, string endpoint)