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.
17 lines
520 B
C#
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;
|
|
}
|
|
} |