mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-24 02:46:44 +00:00
feat(BRIDGE-376): catch gluon errors related to label uniqueness constrainst...
This commit is contained in:
@ -29,6 +29,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/gluon/db"
|
||||
"github.com/ProtonMail/gluon/reporter"
|
||||
"github.com/ProtonMail/gluon/watcher"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal"
|
||||
@ -70,6 +72,8 @@ type Service struct {
|
||||
eventPollWaitersLock sync.Mutex
|
||||
eventSubscription events.Subscription
|
||||
eventWatcher *watcher.Watcher[events.Event]
|
||||
|
||||
sentryReporter reporter.Reporter
|
||||
}
|
||||
|
||||
func NewService(
|
||||
@ -82,6 +86,7 @@ func NewService(
|
||||
eventTimeout time.Duration,
|
||||
panicHandler async.PanicHandler,
|
||||
eventSubscription events.Subscription,
|
||||
sentryReporter reporter.Reporter,
|
||||
) *Service {
|
||||
return &Service{
|
||||
cpc: cpc.NewCPC(),
|
||||
@ -99,6 +104,7 @@ func NewService(
|
||||
panicHandler: panicHandler,
|
||||
eventSubscription: eventSubscription,
|
||||
eventWatcher: eventSubscription.Add(events.ConnStatusDown{}, events.ConnStatusUp{}),
|
||||
sentryReporter: sentryReporter,
|
||||
}
|
||||
}
|
||||
|
||||
@ -414,6 +420,14 @@ func (s *Service) handleEventError(ctx context.Context, lastEventID string, even
|
||||
return subscriberName, fmt.Errorf("failed to handle event due to server error: %w", err)
|
||||
}
|
||||
|
||||
if db.IsUniqueLabelConstraintError(err) {
|
||||
if err := s.sentryReporter.ReportMessageWithContext("Unique label constraint error occurred on event", reporter.Context{
|
||||
"err": err,
|
||||
}); err != nil {
|
||||
s.log.WithError(err).Error("Failed to report label constraint error to sentry")
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, the error is a client-side issue; notify bridge to handle it.
|
||||
s.log.WithField("event", event).Warn("Failed to handle API event")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user