Skip to content

Commit

Permalink
Merge pull request #28 from agouil/more-verbose-errors
Browse files Browse the repository at this point in the history
More verbose error messages
  • Loading branch information
ajbosco authored Jul 26, 2022
2 parents 656fb67 + 6633f4f commit 79cbac0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions segment/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func (c *Client) doRequest(method, endpoint string, data interface{}) ([]byte, e
case http.StatusUnauthorized:
return nil, &SegmentApiError{Message: "invalid access token", Code: resp.StatusCode}
case http.StatusForbidden:
return nil, &SegmentApiError{Message: "unauthorized access to endpoint", Code: resp.StatusCode}
return nil, &SegmentApiError{Message: fmt.Sprintf("unauthorized access to endpoint: %s", endpoint), Code: resp.StatusCode}
case http.StatusNotFound:
return nil, &SegmentApiError{Message: "the requested uri does not exist", Code: resp.StatusCode}
return nil, &SegmentApiError{Message: fmt.Sprintf("the requested uri does not exist: %s", uri), Code: resp.StatusCode}
case http.StatusBadRequest, http.StatusInternalServerError:
return nil, handleErrorRequest(resp.Body)
case http.StatusTooManyRequests:
Expand All @@ -103,7 +103,7 @@ func handleErrorRequest(body io.ReadCloser) error {
var segmentErr SegmentApiError
err = json.Unmarshal(errBody, &segmentErr)
if err != nil {
return fmt.Errorf("request error unkown %s", errBody)
return fmt.Errorf("request error unknown: %s", errBody)
}

return &segmentErr
Expand Down
2 changes: 1 addition & 1 deletion segment/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func Test_doRequest_httpError_badRequestUnstructured(t *testing.T) {
setup()
defer teardown()

expected := "request error unkown bad request\n"
expected := "request error unknown: bad request\n"

mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, "bad request", 400)
Expand Down

0 comments on commit 79cbac0

Please sign in to comment.