Skip to content

Commit

Permalink
roblox/api: handle http errors
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Oct 21, 2023
1 parent afd9f19 commit 85535dc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions roblox/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ func Request(method, service, endpoint string, v interface{}) error {
}
defer resp.Body.Close()

if resp.StatusCode >= 400 {
if resp.StatusCode != http.StatusOK {
// Return the given API error only if the decoder succeeded
errsResp := new(errorsResponse)
if err := json.NewDecoder(resp.Body).Decode(errsResp); err != nil {
return err
if err := json.NewDecoder(resp.Body).Decode(errsResp); err == nil {
return errsResp
}

return errsResp
return fmt.Errorf("%w: %s", ErrBadStatus, resp.Status)
}

if v != nil {
Expand Down

0 comments on commit 85535dc

Please sign in to comment.