Calling a handler from another handler results in an incorrect return #2724
Answered
by
aldas
HarryPeach
asked this question in
Q&A
|
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? |
Answered by
aldas
Dec 19, 2024
Replies: 1 comment
|
refactor that Calling |
0 replies
Answer selected by
HarryPeach
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refactor that
verifyUsernot 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.NoContentetc will be discarder as response has been "commited"