Skip to content

Commit

Permalink
Differentiate remove device error from push proxy (mattermost#27998)
Browse files Browse the repository at this point in the history
* Differentiate remove device error from push proxy

* Fix variable name
  • Loading branch information
larkox committed Aug 23, 2024
1 parent 62adae1 commit e121beb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions server/channels/app/expirynotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ func (a *App) NotifySessionsExpired() error {

errPush := a.sendToPushProxy(tmpMessage, session)
if errPush != nil {
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypePush, model.NotificationReasonPushProxySendError, tmpMessage.Platform)
reason := model.NotificationReasonPushProxySendError
if errPush.Error() == notificationErrorRemoveDevice {
reason = model.NotificationReasonPushProxyRemoveDevice
}
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypePush, reason, tmpMessage.Platform)
a.NotificationsLog().Error("Failed to send to push proxy",
mlog.String("type", model.NotificationTypePush),
mlog.String("status", model.NotificationStatusNotSent),
mlog.String("reason", model.NotificationReasonPushProxySendError),
mlog.String("reason", reason),
mlog.String("ack_id", tmpMessage.AckId),
mlog.String("push_type", tmpMessage.Type),
mlog.String("user_id", session.UserId),
Expand Down
12 changes: 9 additions & 3 deletions server/channels/app/notification_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
notificationTypeMessage notificationType = "message"
notificationTypeUpdateBadge notificationType = "update_badge"
notificationTypeDummy notificationType = "dummy"

notificationErrorRemoveDevice = "device was reported as removed"
)

type PushNotificationsHub struct {
Expand Down Expand Up @@ -184,11 +186,15 @@ func (a *App) sendPushNotificationToAllSessions(rctx request.CTX, msg *model.Pus

err = a.sendToPushProxy(tmpMessage, session)
if err != nil {
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypePush, model.NotificationReasonPushProxySendError, tmpMessage.Platform)
reason := model.NotificationReasonPushProxySendError
if err.Error() == notificationErrorRemoveDevice {
reason = model.NotificationReasonPushProxyRemoveDevice
}
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypePush, reason, tmpMessage.Platform)
a.NotificationsLog().Error("Failed to send to push proxy",
mlog.String("type", model.NotificationTypePush),
mlog.String("status", model.NotificationStatusNotSent),
mlog.String("reason", model.NotificationReasonPushProxySendError),
mlog.String("reason", reason),
mlog.String("ack_id", tmpMessage.AckId),
mlog.String("push_type", tmpMessage.Type),
mlog.String("user_id", session.UserId),
Expand Down Expand Up @@ -523,7 +529,7 @@ func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Sessio
case model.PushStatusRemove:
a.AttachDeviceId(session.Id, "", session.ExpiresAt)
a.ClearSessionCacheForUser(session.UserId)
return errors.New("device was reported as removed")
return errors.New(notificationErrorRemoveDevice)
case model.PushStatusFail:
return errors.New(pushResponse[model.PushStatusErrorMsg])
}
Expand Down
1 change: 1 addition & 0 deletions server/public/model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
NotificationReasonParseError NotificationReason = "json_parse_error"
NotificationReasonPushProxyError NotificationReason = "push_proxy_error"
NotificationReasonPushProxySendError NotificationReason = "push_proxy_send_error"
NotificationReasonPushProxyRemoveDevice NotificationReason = "push_proxy_remove_device"
NotificationReasonRejectedByPlugin NotificationReason = "rejected_by_plugin"
NotificationReasonSessionExpired NotificationReason = "session_expired"
NotificationReasonChannelMuted NotificationReason = "channel_muted"
Expand Down

0 comments on commit e121beb

Please sign in to comment.