This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
HTTP response code, err
returned by request handlers, and middlewares
#2300
Labels
Milestone
From the definition of buffalo
Handler
: https://pkg.go.dev/github.com/gobuffalo/buffalo#HandlerThis statement also includes the responsibility of setting the HTTP response status correctly. However, sometimes we could omit to set the response code and just returns with
nil
or non-nil
err
which indicates the request was successfully completed (could be 200 by default) or failed (could be 500 by default). In this case, thebuffalo.Response
will not be configured completely, and it could make some confusion on middlewares and the result of what middlewares do.One effect of this issue is gobuffalo/buffalo-pop#19
In this case, the handler did its database job correctly but just returned
nil
without the setting response. As a result, even though the response to the client became 200 (since the returned error isnil
) but thepop
middleware detected it as a failure and the database rollback happened.Another issue affected by this behavior is https://gophers.slack.com/archives/C3MSAFD40/p1658983223965079
(Coping from the original description):
(for the reference) My answer to this issue was:
The text was updated successfully, but these errors were encountered: