diff --git a/internal/helper/helpers.go b/internal/helper/helpers.go index f695087b3d868817324ada6517f08ad04d2b5dee..c9ce6221398c7b1c79d6fcb8f4b9c05b9ac93493 100644 --- a/internal/helper/helpers.go +++ b/internal/helper/helpers.go @@ -19,12 +19,18 @@ const NginxResponseBufferHeader = "X-Accel-Buffering" func Fail500(w http.ResponseWriter, r *http.Request, err error) { http.Error(w, "Internal server error", 500) - captureRavenError(r, err) + if err != nil { + captureRavenError(r, err) + } + printError(r, err) } func LogError(r *http.Request, err error) { - captureRavenError(r, err) + if err != nil { + captureRavenError(r, err) + } + printError(r, err) } diff --git a/internal/helper/helpers_test.go b/internal/helper/helpers_test.go index c26766a8655d33067863dc1e4730c0c09b3621d0..9668058c7a23ce0069459c231b4e91710c1594e4 100644 --- a/internal/helper/helpers_test.go +++ b/internal/helper/helpers_test.go @@ -99,3 +99,14 @@ func TestApplicationJson(t *testing.T) { req.Header.Set("Content-Type", "text/plain") assert.False(t, IsApplicationJson(req), "expected not to match 'text/plain' as 'application/json'") } + +func TestFail500WorksWithNils(t *testing.T) { + body := bytes.NewBuffer(nil) + w := httptest.NewRecorder() + w.Body = body + + Fail500(w, nil, nil) + + assert.Equal(t, http.StatusInternalServerError, w.Code) + assert.Equal(t, "Internal server error\n", body.String()) +}