From 20a9d18ce61c19a115e6ba374b20b22063f88d6f Mon Sep 17 00:00:00 2001 From: Romanenko Alexey Date: Wed, 6 May 2020 18:37:06 +0700 Subject: [PATCH] Check status of response before retry send push (#507) --- gorush/notification_apns.go | 6 +++++- gorush/notification_fcm.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index c4fe903..9a50839 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -389,7 +389,11 @@ Retry: } StatStorage.AddIosError(1) - newTokens = append(newTokens, token) + // We should retry only "retryable" statuses. More info about response: + // https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns + if res.StatusCode >= http.StatusInternalServerError { + newTokens = append(newTokens, token) + } isError = true } diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index 3f17115..1d08c03 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -164,8 +164,13 @@ Retry: } if result.Error != nil { + // We should retry only "retryable" statuses. More info about response: + // https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-plain-text + if !result.Unregistered() { + newTokens = append(newTokens, to) + } isError = true - newTokens = append(newTokens, to) + LogPush(FailedPush, to, req, result.Error) if PushConf.Core.Sync { req.AddLog(getLogPushEntry(FailedPush, to, req, result.Error))