FIX: Delete push subscription on MismatchSenderId error

FIX: Delete push subscription on MismatchSenderId error

This should prevent repeated MismatchSenderId warnings when the VAPID keys have changed.

diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb
index 3a63378..39155a7 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

GitHub sha: 17f1a765

2 Likes