Skip to content

Commit

Permalink
[TT-12193] Add log for event handler webhook (#6310)
Browse files Browse the repository at this point in the history
Co-authored-by: Tit Petric <tit@tyk.io>
  • Loading branch information
titpetric and Tit Petric committed May 27, 2024
1 parent e1ea94a commit b759583
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions gateway/event_handler_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,27 @@ func (w *WebHookHandler) BuildRequest(reqBody string) (*http.Request, error) {
return req, nil
}

// CreateBody will render the webhook event message template.
// If an error occurs, a partially rendered template will be
// returned alongside the error that occured.
func (w *WebHookHandler) CreateBody(em config.EventMessage) (string, error) {
var reqBody bytes.Buffer

if err := w.template.Execute(&reqBody, em); err != nil {
return "", err
}

return reqBody.String(), nil
err := w.template.Execute(&reqBody, em)
return reqBody.String(), err
}

// HandleEvent will be fired when the event handler instance is found in an APISpec EventPaths object during a request chain
func (w *WebHookHandler) HandleEvent(em config.EventMessage) {

// Inject event message into template, render to string
reqBody, _ := w.CreateBody(em)
reqBody, err := w.CreateBody(em)
if err != nil {
// We're just logging the template rendering issue here
// but we're passing on the partial rendered contents
log.WithError(err).WithFields(logrus.Fields{
"prefix": "webhooks",
}).Warn("Webhook template rendering error")
}

// Construct request (method, body, params)
req, err := w.BuildRequest(reqBody)
Expand Down

0 comments on commit b759583

Please sign in to comment.