From 71210ebc8e04d49a6afeeecee842b2e8b53f3c4f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 16 Jun 2022 21:41:22 +0530 Subject: handling server errors in user, manga and anime package --- user/user.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'user/user.go') diff --git a/user/user.go b/user/user.go index 704fed7..0d1cbe5 100644 --- a/user/user.go +++ b/user/user.go @@ -30,14 +30,12 @@ func (c Client) GetSelfUserInfo() (UserInfo, error) { // get data from API var userData UserInfo - var errMessage Error - data := c.requestHandler(endpoint) - json.Unmarshal([]byte(data), &userData) - json.Unmarshal([]byte(data), &errMessage) - - if errMessage.Err != "" { - return userData, errors.New(errMessage.Err + " " + errMessage.Msg) + data, err := c.requestHandler(endpoint) + if err != nil { + return userData, err } + json.Unmarshal([]byte(data), &userData) + return userData, nil } -- cgit v1.2.3