From 7991078385eec5130fa9395236dd77992af65f08 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Wed, 29 Jan 2025 18:57:11 +0000 Subject: [PATCH] fix: correctly parse server response body to log on failure --- webhook/request.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webhook/request.go b/webhook/request.go index 9c4f0bb..8af74cb 100644 --- a/webhook/request.go +++ b/webhook/request.go @@ -7,6 +7,7 @@ import ( "log/slog" "net/http" "time" + "io" "github.com/hotosm/central-webhook/parser" ) @@ -41,6 +42,12 @@ func SendRequest( log.Error("failed to send HTTP request", "error", err) return } + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + log.Error("failed to read response body", "error", err) + return + } + respBodyString := string(respBodyBytes) defer resp.Body.Close() // Check the response status @@ -52,6 +59,6 @@ func SendRequest( "endpoint", apiEndpoint, "requestPayload", eventJson, "responseCode", resp.StatusCode, - "responseBody", resp.Body) + "responseBody", respBodyString) } }