Skip to content

Commit

Permalink
Don't log unsupported webhook events as errors (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Aug 25, 2023
1 parent 1766506 commit 5a9c903
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
commentDeleted = "comment_deleted"
commentUpdated = "comment_updated"
commentCreated = "comment_created"

worklogUpdated = "jira:worklog_updated"
)

type Webhook interface {
Expand Down
8 changes: 6 additions & 2 deletions server/webhook_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion server/webhook_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package main

import (
"github.com/pkg/errors"

"github.com/mattermost/mattermost-plugin-jira/server/utils/types"
)

Expand All @@ -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)
}
}
}
}
Expand Down

0 comments on commit 5a9c903

Please sign in to comment.