diff --git a/cfn/response.go b/cfn/response.go index c262d2a0..7f84f033 100644 --- a/cfn/response.go +++ b/cfn/response.go @@ -5,8 +5,9 @@ package cfn import ( "bytes" "encoding/json" - "errors" + "fmt" "io/ioutil" + "log" "net/http" ) @@ -73,7 +74,8 @@ func (r *Response) sendWith(client httpClient) error { res.Body.Close() if res.StatusCode != 200 { - return errors.New("invalid status code") + log.Printf("StatusCode: %d\nBody: %v\n", res.StatusCode, string(body)) + return fmt.Errorf("invalid status code. got: %d", res.StatusCode) } return nil diff --git a/cfn/response_test.go b/cfn/response_test.go index c6170c7a..c833c2b8 100644 --- a/cfn/response_test.go +++ b/cfn/response_test.go @@ -4,6 +4,7 @@ package cfn import ( "bytes" + "fmt" "io" "net/http" "testing" @@ -68,15 +69,19 @@ func TestRequestForbidden(t *testing.T) { url: "http://pre-signed-S3-url-for-response", } + sc := http.StatusForbidden client := &mockClient{ DoFunc: func(req *http.Request) (*http.Response, error) { assert.NotContains(t, req.Header, "Content-Type") return &http.Response{ - StatusCode: http.StatusForbidden, + StatusCode: sc, Body: nopCloser{bytes.NewBufferString("")}, }, nil }, } - assert.Error(t, r.sendWith(client)) + s := r.sendWith(client) + if assert.Error(t, s) { + assert.Equal(t, fmt.Errorf("invalid status code. got: %d", sc), s) + } }