Commit c03b113f authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab)

Merge branch '99-robustify-helpers' into 'master'

Stop Fail500 and LogError from panicing with nil request or error

Closes #99

See merge request !156
parents 41633621 498f9e2f
......@@ -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)
}
......
......@@ -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())
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment