fix(backend): filter out context.Canceled errors

This commit is contained in:
sam 2023-09-20 15:15:43 +02:00
parent fc1f4d03f1
commit 0e6f3a47f4
No known key found for this signature in database
GPG key ID: B4EF20DDE721CAA1

View file

@ -1,10 +1,12 @@
package server
import (
"context"
"fmt"
"net/http"
"codeberg.org/pronounscc/pronouns.cc/backend/log"
"emperror.dev/errors"
"github.com/getsentry/sentry-go"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
@ -37,9 +39,13 @@ func WrapHandler(hn func(w http.ResponseWriter, r *http.Request) error) http.Han
scope.SetTag("path", rctx.RoutePattern())
})
var eventID *sentry.EventID = nil
if isExpectedError(err) {
log.Infof("expected error in handler for %v %v, ignoring", rctx.RouteMethod, rctx.RoutePattern())
} else {
log.Errorf("error in handler for %v %v: %v", rctx.RouteMethod, rctx.RoutePattern(), err)
eventID := hub.CaptureException(err)
eventID = hub.CaptureException(err)
}
apiErr := APIError{ID: eventID, Code: ErrInternalServerError}
apiErr.prepare()
@ -49,6 +55,10 @@ func WrapHandler(hn func(w http.ResponseWriter, r *http.Request) error) http.Han
}
}
func isExpectedError(err error) bool {
return errors.Is(err, context.Canceled)
}
// APIError is an object returned by the API when an error occurs.
// It implements the error interface and can be returned by handlers.
type APIError struct {