DigitalData.Core/DigitalData.Core.Exceptions.Middleware/GlobalExceptionHandlerOptions.cs
Developer 02 f586e9eb2f Refactor exception handling to use HttpExceptionHandler
Updated GlobalExceptionHandlerOptions to replace HttpExceptionMapping with HttpExceptionHandler. Removed HttpExceptionMapping class and introduced HttpExceptionHandler for managing exceptions in HTTP requests. Added methods for creating specific exception handlers and default handlers for common exceptions, with JSON serialization for error messages.
2025-05-19 15:01:50 +02:00

17 lines
520 B
C#

namespace DigitalData.Core.Exceptions.Middleware;
public class GlobalExceptionHandlerOptions
{
internal readonly Dictionary<Type, HttpExceptionHandler> Handlers = new();
internal HttpExceptionHandler? DefaultHandler { get; private set; }
public GlobalExceptionHandlerOptions Add(HttpExceptionHandler handler, bool setAsDefault = false)
{
if (setAsDefault)
DefaultHandler = handler;
else
Handlers[handler.ExceptionType] = handler;
return this;
}
}