Refactor GlobalExceptionHandlerOptions for better access

Updated the accessibility of the RegisteredMappings field to internal and introduced a DefaultMapping property. Modified the Add method to support setting a mapping as default, with adjusted logic for adding mappings.
This commit is contained in:
Developer 02 2025-05-19 14:30:50 +02:00
parent b38422256c
commit cb7b69a0a2

View File

@ -2,11 +2,16 @@
public class GlobalExceptionHandlerOptions
{
private readonly Dictionary<Type, HttpExceptionMapping> _registeredMappings = new();
internal readonly Dictionary<Type, HttpExceptionMapping> RegisteredMappings = new();
public GlobalExceptionHandlerOptions Add(HttpExceptionMapping mapping)
internal HttpExceptionMapping? DefaultMapping { get; private set; }
public GlobalExceptionHandlerOptions Add(HttpExceptionMapping mapping, bool setAsDefault = false)
{
_registeredMappings[mapping.ExceptionType] = mapping;
if (setAsDefault)
DefaultMapping = mapping;
else
RegisteredMappings[mapping.ExceptionType] = mapping;
return this;
}
}