Skip to content
Snippets Groups Projects
Commit d1eb87d6 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'hotfix/error-catch' into 'release'

Hotfix/error catch

See merge request elixxir/notifications-bot!15
parents fc04b598 b72847ca
Branches
Tags
No related merge requests found
...@@ -82,7 +82,7 @@ func sendNotification(app FBSender, token string) (string, error) { ...@@ -82,7 +82,7 @@ func sendNotification(app FBSender, token string) (string, error) {
resp, err := app.Send(ctx, message) resp, err := app.Send(ctx, message)
if err != nil { if err != nil {
return "", errors.Wrap(err, "Failed to send notification") return resp, errors.Wrapf(err, "Failed to send notification. Response: %+v", resp)
} }
return resp, nil return resp, nil
} }
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf" "gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/utils" "gitlab.com/elixxir/primitives/utils"
"strings"
"time" "time"
) )
...@@ -170,7 +171,19 @@ func notifyUser(fcm *messaging.Client, uid string, fc *firebase.FirebaseComm, db ...@@ -170,7 +171,19 @@ func notifyUser(fcm *messaging.Client, uid string, fc *firebase.FirebaseComm, db
resp, err := fc.SendNotification(fcm, u.Token) resp, err := fc.SendNotification(fcm, u.Token)
if err != nil { if err != nil {
return "", errors.Errorf("Failed to send notification to user with ID %+v: %+v", uid, err) // Catch two firebase errors that we don't want to crash on
// 403 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") {
jww.ERROR.Printf("User with ID %+v has invalid token, unregistering...", uid)
err := db.DeleteUser(uid)
if err != nil {
return "", errors.Wrapf(err, "Failed to remove user registration for uid: %+v", uid)
}
} else {
return "", errors.Wrapf(err, "Failed to send notification to user with ID %+v", uid)
}
} }
return resp, nil return resp, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment