feat(api): enhance PlaidException for detailed error logging and improve GlobalExceptionHandler for specific Plaid errors

This commit is contained in:
Stevan Freeborn
2026-03-11 19:28:15 -05:00
parent cb7ed41296
commit 6c8ee3e203
4 changed files with 30 additions and 8 deletions
@@ -1,3 +1,5 @@
using FiscalOS.Infra.Common;
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
internal sealed class GlobalExceptionHandler( internal sealed class GlobalExceptionHandler(
@@ -11,7 +13,23 @@ internal sealed class GlobalExceptionHandler(
CancellationToken cancellationToken CancellationToken cancellationToken
) )
{ {
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"); logger.LogError(exception, "An unhandled exception occurred");
break;
}
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
@@ -107,7 +107,10 @@ internal sealed class PlaidAccountService : IPlaidAccountService
if (itemResponse.IsSuccessStatusCode is false) if (itemResponse.IsSuccessStatusCode is false)
{ {
throw new PlaidException( throw new PlaidException(
"Unable to retrieve item" "Unable to retrieve item",
itemResponse.Error,
itemResponse.RequestId,
(int?)itemResponse.StatusCode
); );
} }
@@ -33,6 +33,7 @@ public static class ServiceDefaultsExtensions
{ {
logging.IncludeFormattedMessage = true; logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true; logging.IncludeScopes = true;
logging.ParseStateValues = true;
}); });
builder.Services.AddOpenTelemetry() builder.Services.AddOpenTelemetry()