diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 17:33:02 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 17:33:02 +0530 |
commit | dfdd87d16bdb5aac867826d454964c063d6740b9 (patch) | |
tree | 96c8925222ab7ca69aed2b13c1139f169704af18 /user/user.go | |
parent | cf32370298596c8d83c31f792fa66672366f2768 (diff) |
reading error responses from API
Diffstat (limited to 'user/user.go')
-rw-r--r-- | user/user.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/user/user.go b/user/user.go index 9c52150..9f31284 100644 --- a/user/user.go +++ b/user/user.go @@ -18,19 +18,26 @@ package user import ( "encoding/json" + "errors" ) const BASE_URL string = "https://api.myanimelist.net/v2/users" // Get info of logged in user -func (c Client) GetSelfUserInfo() UserInfo { +func (c Client) GetSelfUserInfo() (UserInfo, error) { /* MAL only supports @me for this */ endpoint := BASE_URL + "/@me?fields=anime_statistics" // get data from API var userData UserInfo + var errMessage Error data := c.requestHandler(endpoint) json.Unmarshal([]byte(data), &userData) + json.Unmarshal([]byte(data), &errMessage) - return userData + if errMessage.Err != nil { + return userData, errors.New(errMessage.Err + " " + errMessage.Msg) + } + + return userData, nil } |