Skip to content

Commit 316fa26

Browse files
authored
fix(log): panic when dispatching feedback for bad push notification (i.e with over 500 tokens) (#838)
Co-authored-by: Andrey Gumirov <andreyt45@gmail.com>
1 parent 973e8f3 commit 316fa26

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

notify/notification.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,15 @@ func SendNotification(
261261
}
262262

263263
if cfg.Core.FeedbackURL != "" {
264-
for _, l := range resp.Logs {
264+
var logs []logx.LogPushEntry
265+
266+
if resp != nil {
267+
logs = resp.Logs
268+
} else {
269+
logs = makeErrorLogs(cfg, v, err)
270+
}
271+
272+
for _, l := range logs {
265273
err := DispatchFeedback(ctx, l, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout, cfg.Core.FeedbackHeader)
266274
if err != nil {
267275
logx.LogError.Error(err)
@@ -272,6 +280,28 @@ func SendNotification(
272280
return resp, err
273281
}
274282

283+
// makeErrorLogs creates a list of LogPushEntries for each token in notification
284+
// in case when logs are not returned from PushToXYZ() and error err is not nil
285+
func makeErrorLogs(
286+
cfg *config.ConfYaml,
287+
notification *PushNotification,
288+
err error,
289+
) []logx.LogPushEntry {
290+
if err == nil {
291+
return []logx.LogPushEntry{}
292+
}
293+
294+
logs := make([]logx.LogPushEntry, 0, len(notification.Tokens))
295+
296+
for _, token := range notification.Tokens {
297+
log := logPush(cfg, core.FailedPush, token, notification, err)
298+
299+
logs = append(logs, log)
300+
}
301+
302+
return logs
303+
}
304+
275305
// Run send notification
276306
var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg qcore.TaskMessage) error {
277307
return func(ctx context.Context, msg qcore.TaskMessage) error {

0 commit comments

Comments
 (0)