Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.3k
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: funcverifyUser(c echo.Context)error {...returnc.NoContent(http.StatusOK)}funcgetData(c echo.Context)error {err:=verifyUser(c)[...handleerror,propagateifnecessary]returnc.NoContent(http.StatusInternalServerError)// ERROR: This returns 200 (OK)} Is there an obvious issue I'm missing or another way to approach this? |
BetaWas this translation helpful?Give feedback.
All reactions
refactor thatverifyUser not to usereturn c.NoContent(http.StatusOK) and separates its business logic as separate function - and call that ingetData.
Callingc.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"
Replies: 1 comment
-
refactor that Calling |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 2