From 7c7e740fecfc7e3caef82f8c998f8b63dfc300b0 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 14 Jul 2020 22:52:39 +0800 Subject: [PATCH] fix: check response is nil or not (#532) --- gorush/notification_apns.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 5815c34..d971ae5 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -392,7 +392,7 @@ Retry: // send ios notification res, err := client.Push(notification) - if err != nil || res.StatusCode != 200 { + if err != nil || (res != nil && res.StatusCode != http.StatusOK) { if err == nil { // error message: // ref: https://github.com/sideshow/apns2/blob/master/response.go#L14-L65 @@ -415,13 +415,13 @@ Retry: StatStorage.AddIosError(1) // 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 { + if res != nil && res.StatusCode >= http.StatusInternalServerError { newTokens = append(newTokens, token) } isError = true } - if res.Sent() && !isError { + if res != nil && res.Sent() && !isError { LogPush(SucceededPush, token, req, nil) StatStorage.AddIosSuccess(1) }