Draft for 4.5.x
Filter exception handler
See MAGNOLIA-3595 - Getting issue details... STATUS
Rationale
Right now only way how to handle exceptions thrown by filter is to extend the specific filter and catch the exception in custom class. We should provide a way how to configure exception handler to any filter.
Implementation
New interface - ExceptionHandler
set/get exception list
set/is enabled
void handle(Exception) method
Example implementation of EH - registered exception will be caught and logged under level set with the exception (LoggingExceptionHandler).
ExceptionHandler will be part of AbstractMgnlFilter. If filter have some handler configured all exceptions are caught (doFilter() method in MgnlFilterChain class will by in try block). Catch block then searches if caught exception has some behaviour configured. If yes then will follow this, if not then exception is re-thrown.
Example handler should contain settings if exact exceptions should be treated or if also sub-classes of this exception should be included. Then the level of logging should be set so caught exceptions can be treated accordingly.
2 Comments
Magnolia International
While looking at the recent CSRF fixes, I figured this could be _almost_ already implemented via the
SecurityCallbackFilter
andHttpClientCallback
. Granted, naming isn't great, and maybe we'd want an additional method, such asboolean accepts(Throwable t)
onHttpClientCallback
, but the logic is really the same !Magnolia International
Alternative idea (close to what's proposed in MAGNOLIA-3595 I think) is to have a filter dedicated to exception handling, at the top of the chain:
If we have multi-binding, it could become trivial to inject all known exception handlers.