Fix Llamada a getResultados
This commit is contained in:
@@ -94,8 +94,16 @@ public class ElectoralApiService : IElectoralApiService
|
|||||||
if (!lease.IsAcquired) return null;
|
if (!lease.IsAcquired) return null;
|
||||||
|
|
||||||
var client = _httpClientFactory.CreateClient("ElectoralApiClient");
|
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))
|
if (!string.IsNullOrEmpty(municipioId))
|
||||||
{
|
{
|
||||||
requestUri += $"&municipioId={municipioId}";
|
requestUri += $"&municipioId={municipioId}";
|
||||||
@@ -108,19 +116,16 @@ public class ElectoralApiService : IElectoralApiService
|
|||||||
{
|
{
|
||||||
var response = await client.SendAsync(request);
|
var response = await client.SendAsync(request);
|
||||||
|
|
||||||
// --- APLICAMOS LA MISMA LÓGICA DEFENSIVA ---
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Leemos el contenido como un string primero para poder loguearlo si falla.
|
|
||||||
var contentString = await response.Content.ReadAsStringAsync();
|
var contentString = await response.Content.ReadAsStringAsync();
|
||||||
if (string.IsNullOrEmpty(contentString))
|
if (string.IsNullOrEmpty(contentString))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("La API devolvió 200 OK pero con cuerpo vacío para getResultados. URI: {uri}", requestUri);
|
_logger.LogWarning("La API devolvió 200 OK pero con cuerpo vacío para getResultados. URI: {uri}", requestUri);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonSerializer.Deserialize<ResultadosDto>(contentString);
|
return JsonSerializer.Deserialize<ResultadosDto>(contentString);
|
||||||
}
|
}
|
||||||
catch (JsonException ex)
|
catch (JsonException ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user