diff --git a/server/channels/app/expirynotify.go b/server/channels/app/expirynotify.go index 196a24c1b92cd..154ac051634d1 100644 --- a/server/channels/app/expirynotify.go +++ b/server/channels/app/expirynotify.go @@ -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), diff --git a/server/channels/app/notification_push.go b/server/channels/app/notification_push.go index ceae686b4adfd..fc7a18510b173 100644 --- a/server/channels/app/notification_push.go +++ b/server/channels/app/notification_push.go @@ -37,6 +37,8 @@ const ( notificationTypeMessage notificationType = "message" notificationTypeUpdateBadge notificationType = "update_badge" notificationTypeDummy notificationType = "dummy" + + notificationErrorRemoveDevice = "device was reported as removed" ) type PushNotificationsHub struct { @@ -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), @@ -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]) } diff --git a/server/public/model/notification.go b/server/public/model/notification.go index 3029cfc3e0e10..8249c4e9e56e2 100644 --- a/server/public/model/notification.go +++ b/server/public/model/notification.go @@ -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"