Skip to content

Commit

Permalink
Merge pull request #485 from CircleCI-Public/runner-error-messages
Browse files Browse the repository at this point in the history
CIRCLE-29921 Remove HTTP statuscode info from runner error messages
  • Loading branch information
glenjamin authored Oct 7, 2020
2 parents c7c1710 + 2ef38aa commit 026f9bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Client) DoRequest(req *http.Request, resp interface{}) (statusCode int,
if err != nil {
return httpResp.StatusCode, err
}
return httpResp.StatusCode, &HTTPError{Code: httpResp.StatusCode, Err: errors.New(httpError.Message)}
return httpResp.StatusCode, &HTTPError{Code: httpResp.StatusCode, Message: httpError.Message}
}

if resp != nil {
Expand All @@ -95,19 +95,15 @@ func (c *Client) DoRequest(req *http.Request, resp interface{}) (statusCode int,

type HTTPError struct {
Code int
Err error
Message string
}

func (e *HTTPError) Error() string {
if e.Code == 0 {
e.Code = http.StatusInternalServerError
}
if e.Err != nil {
return fmt.Sprintf("%v (%d-%s)", e.Err, e.Code, http.StatusText(e.Code))
if e.Message != "" {
return e.Message
}
return fmt.Sprintf("response %d (%s)", e.Code, http.StatusText(e.Code))
}

func (e *HTTPError) Unwrap() error {
return e.Err
}
2 changes: 1 addition & 1 deletion api/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestClient_DoRequest(t *testing.T) {

resp := make(map[string]interface{})
statusCode, err := c.DoRequest(r, &resp)
assert.Error(t, err, "the error message (400-Bad Request)")
assert.Error(t, err, "the error message")
assert.Equal(t, statusCode, http.StatusBadRequest)
assert.Check(t, cmp.DeepEqual(resp, map[string]interface{}{}))
})
Expand Down

0 comments on commit 026f9bf

Please sign in to comment.