fix(backend): filter out context.Canceled errors
This commit is contained in:
parent
fc1f4d03f1
commit
0e6f3a47f4
|
@ -1,10 +1,12 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"codeberg.org/pronounscc/pronouns.cc/backend/log"
|
"codeberg.org/pronounscc/pronouns.cc/backend/log"
|
||||||
|
"emperror.dev/errors"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/render"
|
"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())
|
scope.SetTag("path", rctx.RoutePattern())
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Errorf("error in handler for %v %v: %v", rctx.RouteMethod, rctx.RoutePattern(), err)
|
var eventID *sentry.EventID = nil
|
||||||
|
if isExpectedError(err) {
|
||||||
eventID := hub.CaptureException(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)
|
||||||
|
}
|
||||||
apiErr := APIError{ID: eventID, Code: ErrInternalServerError}
|
apiErr := APIError{ID: eventID, Code: ErrInternalServerError}
|
||||||
apiErr.prepare()
|
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.
|
// APIError is an object returned by the API when an error occurs.
|
||||||
// It implements the error interface and can be returned by handlers.
|
// It implements the error interface and can be returned by handlers.
|
||||||
type APIError struct {
|
type APIError struct {
|
||||||
|
|
Loading…
Reference in New Issue