chore: simplify sentry code

This commit is contained in:
kolaente
2024-11-22 12:05:02 +01:00
parent 85823b3e97
commit 8732837596
3 changed files with 9 additions and 27 deletions

View File

@@ -24,7 +24,7 @@ import (
// CanCreate checks if a user can subscribe to an entity
func (sb *Subscription) CanCreate(s *xorm.Session, a web.Auth) (can bool, err error) {
if _, is := a.(*LinkSharing); is {
return false, &ErrGenericForbidden{}
return false, ErrGenericForbidden{}
}
sb.EntityType = getEntityTypeFromString(sb.Entity)
@@ -46,7 +46,7 @@ func (sb *Subscription) CanCreate(s *xorm.Session, a web.Auth) (can bool, err er
// CanDelete checks if a user can delete a subscription
func (sb *Subscription) CanDelete(s *xorm.Session, a web.Auth) (can bool, err error) {
if _, is := a.(*LinkSharing); is {
return false, &ErrGenericForbidden{}
return false, ErrGenericForbidden{}
}
sb.EntityType = getEntityTypeFromString(sb.Entity)

View File

@@ -141,22 +141,19 @@ func setupSentry(e *echo.Echo) {
// Only capture errors not already handled by echo
var herr *echo.HTTPError
if errors.As(err, &herr) && herr.Code > 499 {
var errToReport = err
if herr.Internal == nil {
errToReport = herr.Internal
}
hub := sentryecho.GetHubFromContext(c)
if hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("url", c.Request().URL)
if herr.Internal == nil {
hub.CaptureException(err)
} else {
hub.CaptureException(herr.Internal)
}
hub.CaptureException(errToReport)
})
} else {
if herr.Internal == nil {
sentry.CaptureException(err)
} else {
sentry.CaptureException(herr.Internal)
}
sentry.CaptureException(errToReport)
log.Debugf("Could not add context for sending error '%s' to sentry", err.Error())
}
log.Debugf("Error '%s' sent to sentry", err.Error())