What is the best way to handle multiple implementations of IExceptionHandler
in WebAPI?
config.Services.Replace(typeof(IExceptionHandler), new ExceptionHandlerFilter());
config.Services.Add(typeof(IExceptionHandler), new ValidationExceptionHandlerFilter());
When attempting to register more than 1 implementation, the startup throws an exception:
The service type IExceptionHandler is not supported.\r\nParameter name: serviceType
But the API suggests multiple handlers are supported since there's a ShouldHandle
property to override on ExceptionHandler
class.
You can't register more the a IExceptionHandler
We support registering multiple exception loggers but only a single exception handler.
source:Global Error Handling in ASP.NET Web API
The ShouldHandle
properties is used to get only the exception at the top of the stack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With