diff --git a/release notes/upcoming.md b/release notes/upcoming.md index 074fca582d5..b69e0ac5ce5 100644 --- a/release notes/upcoming.md +++ b/release notes/upcoming.md @@ -11,6 +11,7 @@ Description of feature. ## UX * The consolidated user-supplied options (the final combination of config file options, exported script `options`, environment variables and command-line flags) are now exported back into the `options` script variable and can be accessed from the script. Thanks to @mohanprasaths for working on this! (#681 and #713) +* Improved error messages when outputting results to or executing tests in the Load Impact cloud (#716) ## Bugs fixed! diff --git a/stats/cloud/api_test.go b/stats/cloud/api_test.go index a8d2ce82402..1fc6f58199c 100644 --- a/stats/cloud/api_test.go +++ b/stats/cloud/api_test.go @@ -123,7 +123,7 @@ func TestAuthorizedError(t *testing.T) { assert.Equal(t, 1, called) assert.Nil(t, resp) - assert.EqualError(t, err, ErrNotAuthorized.Error()) + assert.EqualError(t, err, "403 Not allowed [err code 5]") } func TestRetry(t *testing.T) { diff --git a/stats/cloud/client.go b/stats/cloud/client.go index 68a9a416791..ef69faf9944 100644 --- a/stats/cloud/client.go +++ b/stats/cloud/client.go @@ -160,12 +160,6 @@ func checkResponse(r *http.Response) error { return nil } - if r.StatusCode == 401 { - return ErrNotAuthenticated - } else if r.StatusCode == 403 { - return ErrNotAuthorized - } - data, err := ioutil.ReadAll(r.Body) if err != nil { return err @@ -175,6 +169,12 @@ func checkResponse(r *http.Response) error { Error ErrorResponse `json:"error"` } if err := json.Unmarshal(data, &payload); err != nil { + if r.StatusCode == http.StatusUnauthorized { + return ErrNotAuthenticated + } + if r.StatusCode == http.StatusForbidden { + return ErrNotAuthorized + } return errors.Errorf( "Unexpected HTTP error from %s: %d %s", r.Request.URL, @@ -182,6 +182,7 @@ func checkResponse(r *http.Response) error { http.StatusText(r.StatusCode), ) } + payload.Error.Response = r return payload.Error } diff --git a/stats/cloud/errors.go b/stats/cloud/errors.go index 632509ee5f3..fbd2598cb08 100644 --- a/stats/cloud/errors.go +++ b/stats/cloud/errors.go @@ -21,8 +21,8 @@ package cloud import ( + "fmt" "net/http" - "strconv" "strings" "github.com/pkg/errors" @@ -45,8 +45,11 @@ type ErrorResponse struct { func (e ErrorResponse) Error() string { msg := e.Message + if e.Response != nil { + msg = fmt.Sprintf("%d %s", e.Response.StatusCode, msg) + } if e.Code != 0 { - msg = strconv.Itoa(e.Code) + " " + msg + msg = fmt.Sprintf("%s [err code %d]", msg, e.Code) } var details []string