Commit fcc5f946 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-refactor-helper' into 'master'

Refactor error logging helpers

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