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;
|
using Microsoft.AspNetCore.Diagnostics;
|
||||||
|
|
||||||
internal sealed class GlobalExceptionHandler(
|
internal sealed class GlobalExceptionHandler(
|
||||||
@@ -11,7 +13,23 @@ internal sealed class GlobalExceptionHandler(
|
|||||||
CancellationToken cancellationToken
|
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;
|
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ public class PlaidException : Exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlaidException(
|
public PlaidException(
|
||||||
string message,
|
string message,
|
||||||
PlaidError? error = null,
|
PlaidError? error = null,
|
||||||
string? plaidRequestId = null,
|
string? plaidRequestId = null,
|
||||||
int? statusCode = null,
|
int? statusCode = null,
|
||||||
Exception? innerException = null
|
Exception? innerException = null
|
||||||
) : base(message, innerException)
|
) : base(message, innerException)
|
||||||
{
|
{
|
||||||
Error = error;
|
Error = error;
|
||||||
RequestId = plaidRequestId;
|
RequestId = plaidRequestId;
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user