-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow HtmxResponse to be used as return type in error handlers #95
Conversation
Agree about the internal method call. We either need to remove the |
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?) |
The HtmxResponseHandlerMethodReturnValueHandler alone is enough to cover the HtmxResponse return value from normal controller methods and exception handlers Fixes #94
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 |
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