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.
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
public class GlobalExceptionHandlerOptions
|
||||
{
|
||||
internal readonly Dictionary<Type, HttpExceptionMapping> RegisteredMappings = new();
|
||||
internal readonly Dictionary<Type, HttpExceptionHandler> Handlers = new();
|
||||
|
||||
internal HttpExceptionMapping? DefaultMapping { get; private set; }
|
||||
internal HttpExceptionHandler? DefaultHandler { get; private set; }
|
||||
|
||||
public GlobalExceptionHandlerOptions Add(HttpExceptionMapping mapping, bool setAsDefault = false)
|
||||
public GlobalExceptionHandlerOptions Add(HttpExceptionHandler handler, bool setAsDefault = false)
|
||||
{
|
||||
if (setAsDefault)
|
||||
DefaultMapping = mapping;
|
||||
DefaultHandler = handler;
|
||||
else
|
||||
RegisteredMappings[mapping.ExceptionType] = mapping;
|
||||
Handlers[handler.ExceptionType] = handler;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user