Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
4b45e314
Commit
4b45e314
authored
3 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Update firebase error handling for more info & better handling
parent
ff060904
No related branches found
No related tags found
3 merge requests
!21
Release
,
!20
Dev
,
!19
Update firebase error handling for more info & better handling
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notifications/notifications.go
+9
-5
9 additions, 5 deletions
notifications/notifications.go
with
9 additions
and
5 deletions
notifications/notifications.go
+
9
−
5
View file @
4b45e314
...
...
@@ -232,23 +232,27 @@ func notifyUser(ephID int64, data []*pb.NotificationData, apnsClient *apns.ApnsC
}
else
{
resp
,
err
:=
fc
.
SendNotification
(
fc
.
Client
,
u
.
Token
,
notificationsCSV
)
if
err
!=
nil
{
// Catch
two
firebase errors that we don't want to crash on
//
400 and
404 indicate that the token stored is incorrect
// Catch firebase errors that we don't want to crash on
// 404 indicate that the token stored is incorrect
// this means rather than crashing we should log and unregister the user
// 400 can also indicate incorrect token, do extra checking on this (12/27/2021)
// Error documentation: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
// 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
(
"Error sending notification: %+v"
,
err
)
invalidToken
:=
strings
.
Contains
(
err
.
Error
(),
"400"
)
&&
strings
.
Contains
(
err
.
Error
(),
"Invalid registration"
)
if
strings
.
Contains
(
err
.
Error
(),
"404"
)
||
invalidToken
{
jww
.
ERROR
.
Printf
(
"User with Transmission RSA hash %+v has invalid token, unregistering..."
,
u
.
TransmissionRSAHash
)
err
:=
db
.
DeleteUserByHash
(
u
.
TransmissionRSAHash
)
if
err
!=
nil
{
return
errors
.
WithMessagef
(
err
,
"Failed to remove user registration tRSA hash: %+v"
,
u
.
TransmissionRSAHash
)
}
}
else
{
jww
.
ERROR
.
Printf
(
"Error sending notification: %+v"
,
err
)
return
errors
.
WithMessagef
(
err
,
"Failed to send notification to user with tRSA hash %+v"
,
u
.
TransmissionRSAHash
)
}
}
else
{
jww
.
INFO
.
Printf
(
"Notified ephemeral ID %+v [%+v] and received response %+v"
,
ephID
,
u
.
Token
,
resp
)
}
jww
.
INFO
.
Printf
(
"Notified ephemeral ID %+v [%+v] and received response %+v"
,
ephID
,
u
.
Token
,
resp
)
}
}
return
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment