Remove old references and refactor base controller

This commit is contained in:
Sergio Matias Urquin
2025-05-17 21:48:00 -06:00
parent 714e18bb65
commit 2519e1b4fb
2 changed files with 22 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Refit;
@@ -23,8 +24,25 @@ namespace Core.Cerberos.BFF.Api.Controllers
private IActionResult FromAPIResponse<T>(ApiResponse<T> response) where T : class
{
var errorContent = JsonConvert.DeserializeObject<string>(response.Error?.Content ?? string.Empty) ?? string.Empty;
return StatusCode((int)response.StatusCode, (response.Content is not null) ? response.Content : errorContent);
if (response.IsSuccessful)
return StatusCode((int)response.StatusCode, response.Content);
else
{
dynamic errorContent = string.Empty;
try
{
errorContent = JsonConvert.DeserializeObject<string>(response.Error?.Content ?? string.Empty) ?? string.Empty;
}
catch (Exception)
{
errorContent = JsonConvert.DeserializeObject<HttpError>(response.Error?.Content);
if (errorContent?.Error?.ErrorCode is null && errorContent?.Error?.Message is null && errorContent?.Error?.Target is null)
errorContent = JsonConvert.DeserializeObject<GenericErrorResponse>(response.Error?.Content);
}
return StatusCode((int)response.StatusCode, errorContent);
}
}
}
}

View File

@@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildingBlocks.Library" Version="0.0.1" />
<PackageReference Include="Cerberos.Building.Blocks" Version="0.0.3" />
<PackageReference Include="Lib.Architecture.BuildingBlocks" Version="0.9.0-alpha0001" />
<PackageReference Include="Refit" Version="8.0.0" />
</ItemGroup>