Skip to content

Commit

Permalink
Merge pull request #15 from storageos/feature/DEV-1579-nicer-http-errors
Browse files Browse the repository at this point in the history
Add basic http status code formater to api errors
  • Loading branch information
JoeReid authored Aug 11, 2017
2 parents 22bf9e5 + d4c6700 commit 139d85d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,23 @@ func newError(resp *http.Response) *Error {
}

func (e *Error) Error() string {
return fmt.Sprintf("API error (%d): %s", e.Status, e.Message)
var niceStatus string

switch e.Status {
case 400, 500:
niceStatus = "Server failed to process your request. Was the data correct?"
case 401:
niceStatus = "Unauthenticated access of secure endpoint, please retry after authentication"
case 403:
niceStatus = "Forbidden request. Your user cannot perform this action"
case 404:
niceStatus = "Requested object not found. Does this item exist?"
}

if niceStatus != "" {
return fmt.Sprintf("API error (%d): %s", niceStatus, e.Message)
}
return fmt.Sprintf("API error (%d): %s", http.StatusText(e.Status), e.Message)
}

func parseEndpoint(endpoint string, tls bool) (*url.URL, error) {
Expand Down

0 comments on commit 139d85d

Please sign in to comment.