Skip to content
Snippets Groups Projects
Commit 6bdbbd2f authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Merge branch 'hotifx/notification-service-handling' into 'release'

Fix from fcm docs for deletable tokens

See merge request elixxir/notifications-bot!4
parents 78c54cdb 30819fd5
No related branches found
No related tags found
2 merge requests!5Release,!4Fix from fcm docs for deletable tokens
......@@ -208,11 +208,12 @@ func notifyUser(data *pb.NotificationData, apnsClient ApnsSender, fcm *messaging
apns.WithCollapseID(base64.StdEncoding.EncodeToString(u.TransmissionRSAHash)),
apns.WithPushType("alert"))
if err != nil {
jww.ERROR.Printf("Failed to send notification via APNS: %+v", err)
err := db.DeleteUserByHash(u.TransmissionRSAHash)
if err != nil {
return errors.WithMessagef(err, "Failed to remove user registration tRSA hash: %+v", u.TransmissionRSAHash)
}
jww.ERROR.Printf("Failed to send notification via APNS: %+v: %+v", resp, err)
// TODO : Should be re-enabled for specific error cases? deep dive on apns docs may be helpful
//err := db.DeleteUserByHash(u.TransmissionRSAHash)
//if err != nil {
// return errors.WithMessagef(err, "Failed to remove user registration tRSA hash: %+v", u.TransmissionRSAHash)
//}
} else {
jww.INFO.Printf("Notified ephemeral ID %+v [%+v] and received response %+v", data.EphemeralID, u.Token, resp)
}
......@@ -220,10 +221,11 @@ func notifyUser(data *pb.NotificationData, apnsClient ApnsSender, fcm *messaging
resp, err := fc.SendNotification(fcm, u.Token, data)
if err != nil {
// Catch two firebase errors that we don't want to crash on
// 403 and 404 indicate that the token stored is incorrect
// 400 and 404 indicate that the token stored is incorrect
// this means rather than crashing we should log and unregister the user
// Error documentation: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
if strings.Contains(err.Error(), "403") || strings.Contains(err.Error(), "404") {
// Stale token documentation: https://firebase.google.com/docs/cloud-messaging/manage-tokens
if strings.Contains(err.Error(), "400") || strings.Contains(err.Error(), "404") {
jww.ERROR.Printf("User with Transmission RSA hash %+v has invalid token, unregistering...", u.TransmissionRSAHash)
err := db.DeleteUserByHash(u.TransmissionRSAHash)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment