diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-03-06 00:51:36 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-03-06 00:51:36 +0530 |
commit | b6f42d806d0e0f5e59c7615cd1558e75c5b314f1 (patch) | |
tree | c9c014759f62c44520be305a60546d08140876f4 /user/manga | |
parent | 95b8ab702708538ccaf26efd141b448148ac6d6d (diff) |
Exported all the errors so programs using this library can customize error messages.
Diffstat (limited to 'user/manga')
-rw-r--r-- | user/manga/mangalist.go | 5 | ||||
-rw-r--r-- | user/manga/update_mangalist.go | 19 |
2 files changed, 11 insertions, 13 deletions
diff --git a/user/manga/mangalist.go b/user/manga/mangalist.go index 009a65c..af75e9f 100644 --- a/user/manga/mangalist.go +++ b/user/manga/mangalist.go @@ -20,7 +20,6 @@ import ( "encoding/json" "strconv" "fmt" - "errors" e "github.com/MikunoNaka/MAL2Go/errhandlers" u "github.com/MikunoNaka/MAL2Go/util" ) @@ -56,12 +55,12 @@ func (c Client) GetMangaList(user, status, sort string, limit, offset int, field // checks if valid sort is specified if !e.IsValidMangaListSort(sort) { - return userMangaList, errors.New(fmt.Sprintf("GetMangaList: Invalid sort specified: \"%s\"", sort)) + return userMangaList, e.InvalidSortError } // checks if valid status is specified if status != "" && !e.IsValidMangaListStatus(status) { - return userMangaList, errors.New(fmt.Sprintf("GetMangaList: Invalid status specified: \"%s\"", status)) + return userMangaList, e.InvalidStatusError } // get own list if user not specified diff --git a/user/manga/update_mangalist.go b/user/manga/update_mangalist.go index 423a919..2fbbe48 100644 --- a/user/manga/update_mangalist.go +++ b/user/manga/update_mangalist.go @@ -17,7 +17,6 @@ package manga import ( e "github.com/MikunoNaka/MAL2Go/errhandlers" - "errors" "fmt" "net/url" "strconv" @@ -34,7 +33,7 @@ func (c Client)SetStatus(id int, status string) (serverResponse, error) { // checks if specified list status is valid if !e.IsValidMangaListStatus(status) { - return serverResponse{}, errors.New(fmt.Sprintf("SetStatus: Invalid list status: \"%s\"", status)) + return serverResponse{}, e.InvalidStatusError } // data to be sent to the server @@ -87,7 +86,7 @@ func (c Client)SetScore(id int, score int) (serverResponse, error) { // checks if specified score is valid if !e.IsValidScore(score) { - return serverResponse{}, errors.New(fmt.Sprintf("SetScore: Invalid score: %d doesn't lie within 0-10", score)) + return serverResponse{}, e.InvalidScoreError } // data to be sent to the server @@ -104,7 +103,7 @@ func (c Client)SetPriority(id int, priority int) (serverResponse, error) { // checks if specified priority is valid if !e.IsValidPriority(priority) { - return serverResponse{}, errors.New(fmt.Sprintf("SetPriority: Invalid priority: %d doesn't lie within 0-2", priority)) + return serverResponse{}, e.InvalidPriorityError } // data to be sent to the server @@ -121,7 +120,7 @@ func (c Client)SetRereadValue(id int, rereadValue int) (serverResponse, error) { // checks if specified reread value is valid if !e.IsValidRewatchValue(rereadValue) { - return serverResponse{}, errors.New(fmt.Sprintf("SetRereadValue: Invalid rewatch value: %d doesn't lie within 0-5", rereadValue)) + return serverResponse{}, e.InvalidRereadValueError } // data to be sent to the server @@ -177,22 +176,22 @@ func (c Client)UpdateManga(id int, data UpdateMangaData) (serverResponse, error) // checks if specified list status is valid if !e.IsValidMangaListStatus(data.Status) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateManga: Invalid list status: \"%s\"", data.Status)) + return serverResponse{}, e.InvalidStatusError } // checks if specified score is valid if !e.IsValidScore(data.Score) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateManga: Invalid score: %d doesn't lie within 0-10", data.Score)) + return serverResponse{}, e.InvalidScoreError } // checks if specified priority is valid if !e.IsValidPriority(data.Priority) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateManga: Invalid priority: %d doesn't lie within 0-2", data.Priority)) + return serverResponse{}, e.InvalidPriorityError } - // checks if specified rewatch value is valid + // checks if specified reread value is valid if !e.IsValidRewatchValue(data.RereadValue) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateManga: Invalid reread value: %d doesn't lie within 0-5", data.RereadValue)) + return serverResponse{}, e.InvalidRereadValueError } params := url.Values{} |