From 871fe76df5a506b42fd5b5f4bb61d29c890bd0fa Mon Sep 17 00:00:00 2001 From: Nils Date: Sun, 29 May 2022 15:05:13 +0200 Subject: [PATCH] return proper http errors --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 8fb0a32..bb86cb0 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ func ping(w http.ResponseWriter, req *http.Request) { defaultopts = append(defaultopts, "-c10") res := prerunner(req, cmd, cmdopts, defaultopts) if strings.TrimSpace(res) == "" { - fmt.Fprintln(w, http.StatusInternalServerError) + http.Error(w, "500: Internal Server Error", http.StatusInternalServerError) } else { fmt.Fprint(w, strings.TrimSpace(res), "\n") } @@ -188,7 +188,7 @@ func mtr(w http.ResponseWriter, req *http.Request) { defaultopts = append(defaultopts, "-r", "-w", "-c10") res := prerunner(req, cmd, cmdopts, defaultopts) if strings.TrimSpace(res) == "" { - fmt.Fprintln(w, http.StatusInternalServerError) + http.Error(w, "500: Internal Server Error", http.StatusInternalServerError) } else { fmt.Fprint(w, strings.TrimSpace(res), "\n") } @@ -204,7 +204,7 @@ func traceroute(w http.ResponseWriter, req *http.Request) { //defaultopts = append(defaultopts) // no default options for traceroute res := prerunner(req, cmd, cmdopts, defaultopts) if strings.TrimSpace(res) == "" { - fmt.Fprintln(w, http.StatusInternalServerError) + http.Error(w, "500: Internal Server Error", http.StatusInternalServerError) } else { fmt.Fprint(w, strings.TrimSpace(res), "\n") } @@ -220,7 +220,7 @@ func nping(w http.ResponseWriter, req *http.Request) { defaultopts = append(defaultopts, "-c3") res := prerunner(req, cmd, cmdopts, defaultopts) if strings.TrimSpace(res) == "" { - fmt.Fprintln(w, http.StatusInternalServerError) + http.Error(w, "500: Internal Server Error", http.StatusInternalServerError) } else { fmt.Fprint(w, strings.TrimSpace(res), "\n") }