FIX: Delete push subscription on MismatchSenderId error

This should prevent repeated MismatchSenderId warnings when the VAPID keys have changed.
This commit is contained in:
Gerhard Schlager 2019-02-15 17:40:33 +01:00
parent 159dd69fcb
commit 17f1a76570
1 changed files with 13 additions and 9 deletions

View File

@ -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