24 lines
745 B
C#
24 lines
745 B
C#
|
|
using Microsoft.AspNetCore.Diagnostics;
|
||
|
|
|
||
|
|
namespace IdentityShroud.Api;
|
||
|
|
|
||
|
|
public class GlobalExceptionHandler : IExceptionHandler
|
||
|
|
{
|
||
|
|
private readonly ILogger<GlobalExceptionHandler> _logger;
|
||
|
|
|
||
|
|
public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
|
||
|
|
=> _logger = logger;
|
||
|
|
|
||
|
|
public async ValueTask<bool> TryHandleAsync(
|
||
|
|
HttpContext httpContext,
|
||
|
|
Exception exception,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
_logger.LogError(exception, "Exception type: {Type}, Message: {Message}",
|
||
|
|
exception.GetType().Name, exception.Message);
|
||
|
|
|
||
|
|
// Return false to let other handlers or the default handle it
|
||
|
|
// Return true to mark it as handled
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|