Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple implementations of IExceptionHandler

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.

like image 935
Phill Avatar asked Sep 29 '22 15:09

Phill


1 Answers

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

like image 65
giammin Avatar answered Oct 07 '22 07:10

giammin