From bea752f7d098eea8010e0cf958c1f02ea26fd901 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Tue, 21 Oct 2025 18:51:22 -0300 Subject: [PATCH] Fix Llamada a getResultados --- .../Services/ElectoralApiService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Elecciones-Web/src/Elecciones.Infrastructure/Services/ElectoralApiService.cs b/Elecciones-Web/src/Elecciones.Infrastructure/Services/ElectoralApiService.cs index 7839198..012147d 100644 --- a/Elecciones-Web/src/Elecciones.Infrastructure/Services/ElectoralApiService.cs +++ b/Elecciones-Web/src/Elecciones.Infrastructure/Services/ElectoralApiService.cs @@ -94,8 +94,16 @@ public class ElectoralApiService : IElectoralApiService if (!lease.IsAcquired) return null; var client = _httpClientFactory.CreateClient("ElectoralApiClient"); - var requestUri = $"/api/resultados/getResultados?distritoId={distritoId}&seccionId={seccionId}&categoriaId={categoriaId}"; + // Construimos la URL base únicamente con los parámetros obligatorios. + var requestUri = $"/api/resultados/getResultados?distritoId={distritoId}&categoriaId={categoriaId}"; + + // Añadimos 'seccionId' a la URL SOLO si tiene un valor válido. + // Esto evita que se genere el problemático "&seccionId=" cuando es nulo o vacío. + if (!string.IsNullOrEmpty(seccionId)) + { + requestUri += $"&seccionId={seccionId}"; + } if (!string.IsNullOrEmpty(municipioId)) { requestUri += $"&municipioId={municipioId}"; @@ -108,19 +116,16 @@ public class ElectoralApiService : IElectoralApiService { var response = await client.SendAsync(request); - // --- APLICAMOS LA MISMA LÓGICA DEFENSIVA --- if (response.IsSuccessStatusCode) { try { - // Leemos el contenido como un string primero para poder loguearlo si falla. var contentString = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(contentString)) { _logger.LogWarning("La API devolvió 200 OK pero con cuerpo vacío para getResultados. URI: {uri}", requestUri); return null; } - return JsonSerializer.Deserialize(contentString); } catch (JsonException ex)