From adc7fa2f78e2c824815840a17ad9f986c27a6c1b Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 11 Jun 2024 09:08:21 -0400 Subject: [PATCH] Tweak handling of responses in webhooks Signed-off-by: Peter Broadhurst --- internal/events/webhooks.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/events/webhooks.go b/internal/events/webhooks.go index 77101bab..83f03bc1 100644 --- a/internal/events/webhooks.go +++ b/internal/events/webhooks.go @@ -19,6 +19,7 @@ package events import ( "context" "crypto/tls" + "io" "net" "net/url" "time" @@ -103,12 +104,10 @@ func (w *webhookAction) attemptBatch(ctx context.Context, batchNumber int64, att if w.isAddressBlocked(addr) { return i18n.NewError(ctx, tmmsgs.MsgBlockWebhookAddress, addr, u.Hostname()) } - var resBody []byte req := w.client.R(). SetContext(ctx). SetBody(events). - SetResult(&resBody). - SetError(&resBody) + SetDoNotParseResponse(true) req.Header.Set("Content-Type", "application/json") for h, v := range w.spec.Headers { req.Header.Set(h, v) @@ -118,7 +117,9 @@ func (w *webhookAction) attemptBatch(ctx context.Context, batchNumber int64, att log.L(ctx).Errorf("Webhook %s (%s) batch=%d attempt=%d: %s", *w.spec.URL, u, batchNumber, attempt, err) return i18n.NewError(ctx, tmmsgs.MsgWebhookErr, err) } + defer res.RawBody().Close() if res.IsError() { + resBody, _ := io.ReadAll(res.RawBody()) log.L(ctx).Errorf("Webhook %s (%s) [%d] batch=%d attempt=%d: %s", *w.spec.URL, u, res.StatusCode(), batchNumber, attempt, resBody) err = i18n.NewError(ctx, tmmsgs.MsgWebhookFailedStatus, res.StatusCode()) }