feat(api): enhance PlaidException for detailed error logging and improve GlobalExceptionHandler for specific Plaid errors
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -33,6 +33,7 @@ public static class ServiceDefaultsExtensions
|
||||
{
|
||||
logging.IncludeFormattedMessage = true;
|
||||
logging.IncludeScopes = true;
|
||||
logging.ParseStateValues = true;
|
||||
});
|
||||
|
||||
builder.Services.AddOpenTelemetry()
|
||||
|
||||
Reference in New Issue
Block a user