Skip to content

Commit

Permalink
Fix error handling for new API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolveix committed Jul 4, 2024
1 parent d9d1525 commit 213b8df
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,9 @@ func (c *UserContext) makeRequestNew(method string, endpoint string, body any, o
return nil, fmt.Errorf("error making request: %w", err)
}

var genericResponse apiGenericResponseN

if resp != nil {
if object != nil {
if err = json.Unmarshal(resp, &object); err != nil {
return nil, fmt.Errorf("error unmarshalling response: %w", err)
}
} else if err = json.Unmarshal(resp, &genericResponse); err == nil {
if genericResponse.Message != "" {
return nil, errors.New(genericResponse.Type + ": " + genericResponse.Message)
}
return nil, errors.New(genericResponse.Type)
if resp != nil && object != nil {
if err = json.Unmarshal(resp, &object); err != nil {
return nil, fmt.Errorf("error unmarshalling response: %w", err)
}
}

Expand Down

0 comments on commit 213b8df

Please sign in to comment.