Skip to content

Commit

Permalink
Improve error handling for user info API call
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed May 7, 2024
1 parent 65116b9 commit 1bf230b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions auth/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,15 @@ func (t *Tokens) GetUserInfo() (*UserInfo, error) {
return nil, err
}
defer resp.Body.Close()

contents, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
if err != nil {
return nil, fmt.Errorf("unable to retrieve user info. Status code %d", resp.StatusCode)
}
}
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to retrieve user info. Status code %d", resp.StatusCode)
}

var userInfo UserInfo

if err = json.Unmarshal(contents, &userInfo); err != nil {
Expand Down

0 comments on commit 1bf230b

Please sign in to comment.