Skip to content

Commit

Permalink
fix: correctly parse server response body to log on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 29, 2025
1 parent 4716bbc commit 7991078
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion webhook/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"net/http"
"time"
"io"

"github.com/hotosm/central-webhook/parser"
)
Expand Down Expand Up @@ -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
Expand All @@ -52,6 +59,6 @@ func SendRequest(
"endpoint", apiEndpoint,
"requestPayload", eventJson,
"responseCode", resp.StatusCode,
"responseBody", resp.Body)
"responseBody", respBodyString)
}
}

0 comments on commit 7991078

Please sign in to comment.