diff --git a/src/FiscalOS.API/Common/GlobalExceptionHandler.cs b/src/FiscalOS.API/Common/GlobalExceptionHandler.cs index 1df1fd4..dab0c4e 100644 --- a/src/FiscalOS.API/Common/GlobalExceptionHandler.cs +++ b/src/FiscalOS.API/Common/GlobalExceptionHandler.cs @@ -1,3 +1,5 @@ +using FiscalOS.Infra.Common; + using Microsoft.AspNetCore.Diagnostics; internal sealed class GlobalExceptionHandler( @@ -11,7 +13,23 @@ internal sealed class GlobalExceptionHandler( CancellationToken cancellationToken ) { - logger.LogError(exception, "An unhandled exception occurred"); + switch (exception) + { + case PlaidException plaidException: + logger.LogError( + plaidException, + "Unhandled Plaid exception. PlaidRequestId: {PlaidRequestId}, PlaidStatusCode: {PlaidStatusCode}, PlaidErrorCode: {PlaidErrorCode}, PlaidErrorType: {PlaidErrorType}, PlaidErrorMessage: {PlaidErrorMessage}", + plaidException.RequestId, + plaidException.StatusCode, + plaidException.ErrorCode, + plaidException.ErrorType, + plaidException.ErrorMessage + ); + break; + default: + logger.LogError(exception, "An unhandled exception occurred"); + break; + } httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; diff --git a/src/FiscalOS.Infra/Accounts/Plaid/PlaidAccountService.cs b/src/FiscalOS.Infra/Accounts/Plaid/PlaidAccountService.cs index 69cd4e6..87f65f0 100644 --- a/src/FiscalOS.Infra/Accounts/Plaid/PlaidAccountService.cs +++ b/src/FiscalOS.Infra/Accounts/Plaid/PlaidAccountService.cs @@ -107,7 +107,10 @@ internal sealed class PlaidAccountService : IPlaidAccountService if (itemResponse.IsSuccessStatusCode is false) { throw new PlaidException( - "Unable to retrieve item" + "Unable to retrieve item", + itemResponse.Error, + itemResponse.RequestId, + (int?)itemResponse.StatusCode ); } diff --git a/src/FiscalOS.Infra/Common/PlaidException.cs b/src/FiscalOS.Infra/Common/PlaidException.cs index 378e64b..a8ab69a 100644 --- a/src/FiscalOS.Infra/Common/PlaidException.cs +++ b/src/FiscalOS.Infra/Common/PlaidException.cs @@ -22,12 +22,12 @@ public class PlaidException : Exception } public PlaidException( - string message, - PlaidError? error = null, - string? plaidRequestId = null, - int? statusCode = null, - Exception? innerException = null - ) : base(message, innerException) + string message, + PlaidError? error = null, + string? plaidRequestId = null, + int? statusCode = null, + Exception? innerException = null + ) : base(message, innerException) { Error = error; RequestId = plaidRequestId; diff --git a/src/FiscalOS.ServiceDefaults/ServiceDefaultsExtensions.cs b/src/FiscalOS.ServiceDefaults/ServiceDefaultsExtensions.cs index 28936eb..3ed6fc8 100644 --- a/src/FiscalOS.ServiceDefaults/ServiceDefaultsExtensions.cs +++ b/src/FiscalOS.ServiceDefaults/ServiceDefaultsExtensions.cs @@ -33,6 +33,7 @@ public static class ServiceDefaultsExtensions { logging.IncludeFormattedMessage = true; logging.IncludeScopes = true; + logging.ParseStateValues = true; }); builder.Services.AddOpenTelemetry()