Commit 498f9e2f authored by Nick Thomas's avatar Nick Thomas

Stop Fail500 and LogError from panicing with nil request or error

parent 41633621
...@@ -19,12 +19,18 @@ const NginxResponseBufferHeader = "X-Accel-Buffering" ...@@ -19,12 +19,18 @@ const NginxResponseBufferHeader = "X-Accel-Buffering"
func Fail500(w http.ResponseWriter, r *http.Request, err error) { func Fail500(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, "Internal server error", 500) http.Error(w, "Internal server error", 500)
if err != nil {
captureRavenError(r, err) captureRavenError(r, err)
}
printError(r, err) printError(r, err)
} }
func LogError(r *http.Request, err error) { func LogError(r *http.Request, err error) {
if err != nil {
captureRavenError(r, err) captureRavenError(r, err)
}
printError(r, err) printError(r, err)
} }
......
...@@ -99,3 +99,14 @@ func TestApplicationJson(t *testing.T) { ...@@ -99,3 +99,14 @@ func TestApplicationJson(t *testing.T) {
req.Header.Set("Content-Type", "text/plain") req.Header.Set("Content-Type", "text/plain")
assert.False(t, IsApplicationJson(req), "expected not to match 'text/plain' as 'application/json'") 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