Skip to content

Commit

Permalink
Better handle unknown errors (#32)
Browse files Browse the repository at this point in the history
* Better handle unknown errors

* Better handle unknown errors#2
  • Loading branch information
edsonmichaque committed Aug 10, 2023
1 parent 3c06be9 commit 4643c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ type APIError struct {
}

func (e APIError) Error() string {
err := "unknown error"
if len(e.Errors) != 0 {
err = e.Errors[0]
}

return fmt.Sprintf(
"%v %v: %v %v",
e.Response.Request.Method,
e.Response.Request.URL,
e.Response.StatusCode,
e.Errors[0],
err,
)
}

Expand Down
3 changes: 2 additions & 1 deletion portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ func checkError(resp *APIResponse) error {
}

if err := json.Unmarshal(resp.Body, &e); err != nil {
return err
return errors.New(http.StatusText(resp.Response.StatusCode))
}

return e
}
}
Expand Down

0 comments on commit 4643c02

Please sign in to comment.