Calling a handler from another handler results in an incorrect return #2724
-
Hey, I'm writing a handler that needs to call another handler (i.e. I have a POST handler that verifies a users access, and I'd like another POST handler "getData" that calls the access handler first) When I do this however, the return value of the "getData" handler is always that of the verify handler. Short Example: func verifyUser(c echo.Context) error {
...
return c.NoContent(http.StatusOK)
}
func getData(c echo.Context) error {
err := verifyUser(c)
[... handle error, propagate if necessary]
return c.NoContent(http.StatusInternalServerError) // ERROR: This returns 200 (OK)
} Is there an obvious issue I'm missing or another way to approach this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
refactor that Calling |
Beta Was this translation helpful? Give feedback.
refactor that
verifyUser
not to usereturn c.NoContent(http.StatusOK)
and separates its business logic as separate function - and call that ingetData
.Calling
c.NoContent(http.StatusOK)
means that the response will be sent immeteately to the client and any call toc.NoContent
etc will be discarder as response has been "commited"