Skip to content

Commit

Permalink
Tweak handling of responses in webhooks
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
  • Loading branch information
peterbroadhurst committed Jun 11, 2024
1 parent 0015555 commit adc7fa2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/events/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package events
import (
"context"
"crypto/tls"
"io"
"net"
"net/url"
"time"
Expand Down Expand Up @@ -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)
Expand All @@ -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())
}
Expand Down

0 comments on commit adc7fa2

Please sign in to comment.