Skip to content
Snippets Groups Projects
Commit 498f9e2f authored by Nick Thomas's avatar Nick Thomas
Browse files

Stop Fail500 and LogError from panicing with nil request or error

parent 41633621
No related branches found
No related tags found
1 merge request!156Stop Fail500 and LogError from panicing with nil request or error
Loading
Loading
@@ -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)
}
 
Loading
Loading
Loading
Loading
@@ -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())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment