From 5a9c9038a12dd242050299af34f7b19e861ea118 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Fri, 25 Aug 2023 13:13:48 +0200 Subject: [PATCH] Don't log unsupported webhook events as errors (#964) --- server/webhook.go | 2 ++ server/webhook_parser.go | 8 ++++++-- server/webhook_worker.go | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/webhook.go b/server/webhook.go index 0cdfbf30b..ea4d0e1e5 100644 --- a/server/webhook.go +++ b/server/webhook.go @@ -20,6 +20,8 @@ const ( commentDeleted = "comment_deleted" commentUpdated = "comment_updated" commentCreated = "comment_created" + + worklogUpdated = "jira:worklog_updated" ) type Webhook interface { diff --git a/server/webhook_parser.go b/server/webhook_parser.go index fd643f584..1dfe5448d 100644 --- a/server/webhook_parser.go +++ b/server/webhook_parser.go @@ -17,6 +17,8 @@ import ( "github.com/mattermost/mattermost-server/v6/model" ) +var errWebhookeventUnsupported = errors.New("Unsupported webhook event") + var webhookWrapperFunc func(wh Webhook) Webhook func ParseWebhook(bb []byte) (wh Webhook, err error) { @@ -76,14 +78,16 @@ func ParseWebhook(bb []byte) (wh Webhook, err error) { wh, err = parseWebhookCommentUpdated(jwh) case commentDeleted: wh, err = parseWebhookCommentDeleted(jwh) + case worklogUpdated: + // not supported default: - err = errors.Errorf("Unsupported webhook event: %v", jwh.WebhookEvent) + err = errors.Wrapf(errWebhookeventUnsupported, "event: %v", jwh.WebhookEvent) } if err != nil { return nil, err } if wh == nil { - return nil, errors.Errorf("Unsupported webhook data: %v", jwh.WebhookEvent) + return nil, errors.Wrapf(errWebhookeventUnsupported, "event: %v", jwh.WebhookEvent) } // For HTTP testing, so we can capture the output of the interface diff --git a/server/webhook_worker.go b/server/webhook_worker.go index a008e665f..859cc6bcc 100644 --- a/server/webhook_worker.go +++ b/server/webhook_worker.go @@ -4,6 +4,8 @@ package main import ( + "github.com/pkg/errors" + "github.com/mattermost/mattermost-plugin-jira/server/utils/types" ) @@ -22,7 +24,11 @@ func (ww webhookWorker) work() { for msg := range ww.workQueue { err := ww.process(msg) if err != nil { - ww.p.errorf("WebhookWorker id: %d, error processing, err: %v", ww.id, err) + if errors.Is(err, errWebhookeventUnsupported) { + ww.p.debugf("WebhookWorker id: %d, error processing, err: %v", ww.id, err) + } else { + ww.p.errorf("WebhookWorker id: %d, error processing, err: %v", ww.id, err) + } } } }