Include webhook response in error message.

pull/1516/head
Josh Drake 10 months ago
parent c07124e374
commit 12bb5d16a4
No known key found for this signature in database

@ -8,9 +8,11 @@ import (
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"io"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"strings"
"text/template" "text/template"
"time" "time"
@ -219,7 +221,11 @@ retry:
goto retry goto retry
} }
if resp.StatusCode >= 400 { if resp.StatusCode >= 400 {
return nil, fmt.Errorf("Webhook server responded with %d", resp.StatusCode) b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Webhook server responded with %d", resp.StatusCode)
}
return nil, fmt.Errorf("Webhook server responded with %d: %s", resp.StatusCode, strings.TrimSpace(string(b)))
} }
respBody := &webhook.ResponseBody{} respBody := &webhook.ResponseBody{}

@ -465,7 +465,7 @@ func TestWebhook_Do(t *testing.T) {
}, },
errStatusCode: 404, errStatusCode: 404,
serverErrMsg: "item not found", serverErrMsg: "item not found",
expectErr: errors.New("Webhook server responded with 404"), expectErr: errors.New("Webhook server responded with 404: item not found"),
}, },
} }
for name, tc := range tests { for name, tc := range tests {

Loading…
Cancel
Save