Closed wimdeblauwe closed 11 months ago
Agree about the internal method call. We either need to remove the proxyBeanMethods
flag or ship them out to a separate @Configuration
(and wire them back into the constructor).
Isn’t the interceptor mainly doing exactly the same work as the return value handler? I’m not sure it needs to be done twice. (So all the code from the helper could just be migrated to the return value handler?)
Thanks for the input @dsyer. You are correct that there is no more need for the intercepter, the return value handler works for all cases. I have updated the code accordingly.
LGTM
This is now released and I blogged to showcase the feature: https://www.wimdeblauwe.com/blog/2023/12/14/htmx-global-error-handler/
@wimdeblauwe is there a way to restrict the @ExceptionHandler
to htmx requests only?
According to https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc/, you can define a HttpServletRequest parameter in your exception handler. You could read the headers there to check if it is an htmx request or not.
Yeah, I am aware of that. I meant an annotation like the one we have for the controller methods.
That would be nice if that is possible, but no clue if there are extension points to implement that.
This PR adds an
HandlerMethodReturnValueHandler
implementation to handle aHtmxResponse
object as a return type from an error handler. A lot of code is the same as inHtmxViewHandlerInterceptor
. For that reason, I extractedHtmxResponseHelper
.@dsyer and @odrotbohm Would love you feedback on this PR. Especially doubting if the method calls I am doing in the
HtmxMvcAutoConfiguration
are correct given that@AutoConfiguration
hasproxyBeanMethods
set tofalse
, but I don't know of another way to make it work.Fixes #94