Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture some basic errors in the server via sentry #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down