From 66262392c3e3a6ef214f84b5992f2dfed1350de5 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 4 Apr 2020 09:21:30 +0200 Subject: [PATCH] cmd/strelaypoolsrv: Correctly account status codes, tweak status codes --- cmd/strelaypoolsrv/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/strelaypoolsrv/main.go b/cmd/strelaypoolsrv/main.go index 24604206b..6c3e38a31 100644 --- a/cmd/strelaypoolsrv/main.go +++ b/cmd/strelaypoolsrv/main.go @@ -334,10 +334,10 @@ func mimeTypeForFile(file string) string { func handleRequest(w http.ResponseWriter, r *http.Request) { timer := prometheus.NewTimer(apiRequestsSeconds.WithLabelValues(r.Method)) - lw := NewLoggingResponseWriter(w) - + w = NewLoggingResponseWriter(w) defer func() { timer.ObserveDuration() + lw := w.(*loggingResponseWriter) apiRequestsTotal.WithLabelValues(r.Method, strconv.Itoa(lw.statusCode)).Inc() }() @@ -397,7 +397,7 @@ func handlePostRequest(w http.ResponseWriter, r *http.Request) { if debug { log.Println("Failed to parse payload") } - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -406,7 +406,7 @@ func handlePostRequest(w http.ResponseWriter, r *http.Request) { if debug { log.Println("Failed to parse URI", newRelay.URL) } - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -415,7 +415,7 @@ func handlePostRequest(w http.ResponseWriter, r *http.Request) { if debug { log.Println("Failed to split URI", newRelay.URL) } - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusBadRequest) return }