Commit 71afdfee authored by Francisco Javier López's avatar Francisco Javier López Committed by Nick Thomas

Refactor error logging helpers

parent 9023f0b2
......@@ -21,8 +21,7 @@ import (
const NginxResponseBufferHeader = "X-Accel-Buffering"
func Fail500(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, "Internal server error", 500)
func LogError(r *http.Request, err error) {
if err != nil {
captureRavenError(r, err)
}
......@@ -30,24 +29,19 @@ func Fail500(w http.ResponseWriter, r *http.Request, err error) {
printError(r, err)
}
func LogError(r *http.Request, err error) {
if err != nil {
captureRavenError(r, err)
}
func CaptureAndFail(w http.ResponseWriter, r *http.Request, err error, msg string, code int) {
http.Error(w, msg, code)
LogError(r, err)
}
printError(r, err)
func Fail500(w http.ResponseWriter, r *http.Request, err error) {
CaptureAndFail(w, r, err, "Internal server error", http.StatusInternalServerError)
}
func RequestEntityTooLarge(w http.ResponseWriter, r *http.Request, err error) {
CaptureAndFail(w, r, err, "Request Entity Too Large", http.StatusRequestEntityTooLarge)
}
func CaptureAndFail(w http.ResponseWriter, r *http.Request, err error, msg string, code int) {
http.Error(w, msg, code)
captureRavenError(r, err)
printError(r, err)
}
func printError(r *http.Request, err error) {
if r != nil {
log.WithFields(r.Context(), log.Fields{
......
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