diff options
-rw-r--r-- | user/user.go | 11 | ||||
-rw-r--r-- | user/user.structs.go | 5 |
2 files changed, 14 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 } diff --git a/user/user.structs.go b/user/user.structs.go index b730033..731588d 100644 --- a/user/user.structs.go +++ b/user/user.structs.go @@ -28,3 +28,8 @@ type UserInfo struct { TimeZone string `json:"time_zone"` IsSupporter bool `json:"is_supporter"` } + +type Error struct { + Err string `json:"error"` + Msg string `json:"message"` +} |