solidservices icon indicating copy to clipboard operation
solidservices copied to clipboard

ExceptionFilterAttribute doesn't get hit

Open stevengopmo opened this issue 6 years ago • 1 comments

I've noticed that my Custom ExceptionFilterAttribute doesn't get hit when using this approach to WebApi. Maybe that's the reason you have a try catch in the DelegatingHandlers? Do you know why the normal filtering mechanism doesn't work with this approach? In general, I'm kind of anti try/catch and I think the built-in WebApi approach is generally pretty decent.

Of course, this one small place for catching isn't bad; I guess I'm curious if there's a technical reason.

stevengopmo avatar Apr 11 '18 13:04 stevengopmo

To be honest, I don't know, but I can imagine that exception filters only work on controllers. At a broader level, I think you'd stack delegating handlers (as decorators) to apply exception filtering. As a simplification, this project places the exception handling inside the single delegating handler, because:

  • that's the simplest thing that could possibly work
  • having try-catch statements makes it very clear how things are handled (compared to exception filters, which always freak me out a bit), and it gives you full control.
  • In case the generic handling becomes too much, it can be easily refactored into smaller methods, or even extracted into delegating handlers.

dotnetjunkie avatar Apr 14 '18 14:04 dotnetjunkie