Skip to content

Commit

Permalink
Passthrough all response status codes
Browse files Browse the repository at this point in the history
Rather than only passing 403 and 404 through, and turning other 4xx/5xx responses into 500, pass them all through as-is.

This matches the behaviour of lpa-frontend and avoids logging an unnecessary error message.

#patch
  • Loading branch information
gregtyler committed Oct 16, 2024
1 parent 5a7eeb3 commit ac9d3f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ func errorHandler(tmplError Template, prefix, siriusURL string) func(next Handle
code := http.StatusInternalServerError
message := err.Error()
if status, ok := err.(StatusError); ok {
if status.Code() == http.StatusForbidden || status.Code() == http.StatusNotFound {
code = status.Code()
}
code = status.Code()
}

if statusError, ok := err.(*sirius.StatusError); ok {
Expand Down
6 changes: 3 additions & 3 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestErrorHandlerStatus(t *testing.T) {

wrap := errorHandler(tmplError, "/prefix", "http://sirius")
handler := wrap(func(w http.ResponseWriter, r *http.Request) error {
return StatusError(http.StatusTeapot)
return StatusError(http.StatusInternalServerError)
})

w := httptest.NewRecorder()
Expand All @@ -131,12 +131,12 @@ func TestErrorHandlerStatus(t *testing.T) {
assert.Equal(http.StatusInternalServerError, resp.StatusCode)

assert.Equal(1, tmplError.count)
assert.Equal(errorVars{SiriusURL: "http://sirius", Code: http.StatusInternalServerError, Error: "418 I'm a teapot"}, tmplError.lastVars)
assert.Equal(errorVars{SiriusURL: "http://sirius", Code: http.StatusInternalServerError, Error: "500 Internal Server Error"}, tmplError.lastVars)

data := map[string]string{}
err := json.Unmarshal(logBuf.Bytes(), &data)
assert.Nil(err)
assert.Equal("418 I'm a teapot", data["msg"])
assert.Equal("500 Internal Server Error", data["msg"])
assert.Equal("ERROR", data["level"])
}

Expand Down

0 comments on commit ac9d3f5

Please sign in to comment.