From 3c91bb314da51e1351c05dd0f521a8834461e9b3 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 20 Feb 2017 14:45:37 +0000 Subject: [PATCH] Log response body when content upload fails --- client.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 29784eb..0be306d 100644 --- a/client.go +++ b/client.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/ioutil" + "log" "net/http" "net/url" "path" @@ -556,8 +557,16 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co return nil, err } if res.StatusCode != 200 { + contents, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, HTTPError{ + Message: "Upload request failed - Failed to read response body: " + err.Error(), + Code: res.StatusCode, + } + } + log.Printf("Upload request failed: %s", string(contents)) return nil, HTTPError{ - Message: "Upload request failed", + Message: "Upload request failed" + string(contents), Code: res.StatusCode, } }