From 22678ca4850fe4142bb87466379b886eb57a6556 Mon Sep 17 00:00:00 2001 From: "Jorge Alberto Diaz Orozco (Akiel)" Date: Sun, 28 May 2023 12:07:57 +0200 Subject: [PATCH] Capture some basic errors in the server via sentry --- server.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server.go b/server.go index 5ac8e16..b350263 100644 --- a/server.go +++ b/server.go @@ -5,6 +5,7 @@ import ( "embed" "encoding/json" "fmt" + "github.com/getsentry/sentry-go" "github.com/prometheus/client_golang/prometheus/promhttp" log "github.com/sirupsen/logrus" "golang.org/x/net/html" @@ -37,6 +38,7 @@ func getRouter(ipv4Only bool) (*http.ServeMux, error) { timeout, err := getDefaultTimeout() if err != nil { + sentry.CaptureException(err) log.Errorf("impossible to get default timeout %v", err) http.Error(w, "Internal server error", http.StatusInternalServerError) return @@ -71,6 +73,7 @@ func getRouter(ipv4Only bool) (*http.ServeMux, error) { err = json.NewEncoder(w).Encode(details) if err != nil { + sentry.CaptureException(err) log.Errorf("error occurred when sending the data back to the client %v", err) } }) @@ -108,6 +111,7 @@ func getAddressAndTimeoutFromForm(w http.ResponseWriter, r *http.Request, addres if err := r.ParseForm(); err != nil { _, err := fmt.Fprintf(w, "ParseForm() err: %v", err) if err != nil { + sentry.CaptureException(err) log.Errorf("impossible to write response %v", err) return "", 0, true } @@ -118,6 +122,7 @@ func getAddressAndTimeoutFromForm(w http.ResponseWriter, r *http.Request, addres if r.FormValue("timeout") != "" { timeout, err = strconv.Atoi(r.FormValue("timeout")) if err != nil { + sentry.CaptureException(err) http.Error(w, "Unable to parse timeout", http.StatusBadRequest) return "", 0, true }