From 17f1a765708b5537d1f4c1f0738198b9bb1a09cb Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Fri, 15 Feb 2019 17:40:33 +0100 Subject: [PATCH] FIX: Delete push subscription on MismatchSenderId error This should prevent repeated MismatchSenderId warnings when the VAPID keys have changed. --- app/services/push_notification_pusher.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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