-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
HTTPErrorHandler is ignored if a WrapMiddleware writes the response (red test and fix included) #2498
Comments
You really should not use I think this is misunderstanding how Echo middlewares are executed and how errors are "bubbled up" in middleware chain if err != nil {
c.Echo().HTTPErrorHandler(c, err)
} which means any middleware before and your wrapped middleware is doing error handling as It is not |
Similarly e.GET("/", func(c Context) error {
return c.JSON(http.StatusBadRequest, "nope")
}) will not trigger error handling as it not an error. |
Hi @aldas Thanks for getting back to me, you're probably right, I don't fully understand Echo and how it works. However I think the use case is valid, I'm simplified it further to explain to you:
Any suggestion how best to handle this user case? Preferably without having to refactor the http middleware. |
Also could you ellaborate on:
I'm using Echo as dependency of a framework and it was not my decision to use v5 or Echo, so any additional info it would be great. |
Issue Description
HTTPErrorHandler
is ignored if aWrapMiddleware
writes the response (red test and fix included)Checklist
Expected behaviour
HTTPErrorHandler
should be respected if aWrapMiddleware
writes the response.Actual behaviour
Custom error handling is not respected if a
WrapMiddleware
writes the response instead, the final response is always 200 with an empty body instead of whatever might have been set withHTTPErrorHandler
.Steps to reproduce
The below is a simplified red test
Working code to debug
Replace
echo.WrapMiddleware
on the example above with the overload below:Version/commit
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
The text was updated successfully, but these errors were encountered: