Skip to content

A platform for community discussion. Free, open, simple.

FIX: Delete push subscription on MismatchSenderId error

Gerhard Schlager17f1a765708b
diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb
index 3a633788652..39155a771a3 100644
--- a/app/services/push_notification_pusher.rb
+++ b/app/services/push_notification_pusher.rb
@@ -88,15 +88,19 @@ class PushNotificationPusher
rescue Webpush::ExpiredSubscription
unsubscribe(user, subscription)
rescue Webpush::ResponseError => e
- Discourse.warn_exception(
- e,
- message: "Failed to send push notification",
- env: {
- user_id: user.id,
- endpoint: subscription["endpoint"],
- message: message.to_json
- }
- )
+ if e.response.message == "MismatchSenderId"
+ unsubscribe(user, subscription)
+ else
+ Discourse.warn_exception(
+ e,
+ message: "Failed to send push notification",
+ env: {
+ user_id: user.id,
+ endpoint: subscription["endpoint"],
+ message: message.to_json
+ }
+ )
+ end
end
end
end