Improve observability on FCM errors (#542)
A caller can now observe errors returned from FCM server such as an unauthorized error (401).
This commit is contained in:
parent
eb400aa1d3
commit
5f88e5da5d
|
@ -141,6 +141,34 @@ Retry:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Send Message error
|
// Send Message error
|
||||||
LogError.Error("FCM server send message error: " + err.Error())
|
LogError.Error("FCM server send message error: " + err.Error())
|
||||||
|
|
||||||
|
if req.IsTopic() {
|
||||||
|
if PushConf.Core.Sync {
|
||||||
|
req.AddLog(getLogPushEntry(FailedPush, req.To, req, err))
|
||||||
|
} else if PushConf.Core.FeedbackURL != "" {
|
||||||
|
go func(logger *logrus.Logger, log LogPushEntry, url string, timeout int64) {
|
||||||
|
err := DispatchFeedback(log, url, timeout)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
}
|
||||||
|
}(LogError, getLogPushEntry(FailedPush, req.To, req, err), PushConf.Core.FeedbackURL, PushConf.Core.FeedbackTimeout)
|
||||||
|
}
|
||||||
|
StatStorage.AddAndroidError(1)
|
||||||
|
} else {
|
||||||
|
for _, token := range req.Tokens {
|
||||||
|
if PushConf.Core.Sync {
|
||||||
|
req.AddLog(getLogPushEntry(FailedPush, token, req, err))
|
||||||
|
} else if PushConf.Core.FeedbackURL != "" {
|
||||||
|
go func(logger *logrus.Logger, log LogPushEntry, url string, timeout int64) {
|
||||||
|
err := DispatchFeedback(log, url, timeout)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
}
|
||||||
|
}(LogError, getLogPushEntry(FailedPush, token, req, err), PushConf.Core.FeedbackURL, PushConf.Core.FeedbackTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StatStorage.AddAndroidError(int64(len(req.Tokens)))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ func TestPushToAndroidRightTokenForStringLog(t *testing.T) {
|
||||||
func TestOverwriteAndroidAPIKey(t *testing.T) {
|
func TestOverwriteAndroidAPIKey(t *testing.T) {
|
||||||
PushConf, _ = config.LoadConf("")
|
PushConf, _ = config.LoadConf("")
|
||||||
|
|
||||||
|
PushConf.Core.Sync = true
|
||||||
PushConf.Android.Enabled = true
|
PushConf.Android.Enabled = true
|
||||||
PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
PushConf.Android.APIKey = os.Getenv("ANDROID_API_KEY")
|
||||||
|
|
||||||
|
@ -113,10 +114,14 @@ func TestOverwriteAndroidAPIKey(t *testing.T) {
|
||||||
Message: "Welcome",
|
Message: "Welcome",
|
||||||
// overwrite android api key
|
// overwrite android api key
|
||||||
APIKey: "1234",
|
APIKey: "1234",
|
||||||
|
|
||||||
|
log: &[]LogPushEntry{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// FCM server error: 401 error: 401 Unauthorized (Wrong API Key)
|
// FCM server error: 401 error: 401 Unauthorized (Wrong API Key)
|
||||||
PushToAndroid(req)
|
PushToAndroid(req)
|
||||||
|
|
||||||
|
assert.Len(t, *req.log, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFCMMessage(t *testing.T) {
|
func TestFCMMessage(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue