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 | |
parent | 95b8ab702708538ccaf26efd141b448148ac6d6d (diff) |
Exported all the errors so programs using this library can customize error messages.
Diffstat (limited to 'user')
-rw-r--r-- | user/anime/animelist.go | 5 | ||||
-rw-r--r-- | user/anime/update_animelist.go | 17 | ||||
-rw-r--r-- | user/manga/mangalist.go | 5 | ||||
-rw-r--r-- | user/manga/update_mangalist.go | 19 |
4 files changed, 21 insertions, 25 deletions
diff --git a/user/anime/animelist.go b/user/anime/animelist.go index f6d9965..2840df3 100644 --- a/user/anime/animelist.go +++ b/user/anime/animelist.go @@ -20,7 +20,6 @@ import ( "encoding/json" "strconv" "fmt" - "errors" a "github.com/MikunoNaka/MAL2Go/anime" e "github.com/MikunoNaka/MAL2Go/errhandlers" u "github.com/MikunoNaka/MAL2Go/util" @@ -57,12 +56,12 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int, field // checks if valid sort is specified if !e.IsValidListSort(sort) { - return userAnimeList, errors.New(fmt.Sprintf("GetAnimeList: Invalid sort specified: \"%s\"", sort)) + return userAnimeList, e.InvalidSortError } // checks if valid status is specified if status != "" && !e.IsValidListStatus(status) { - return userAnimeList, errors.New(fmt.Sprintf("GetAnimeList: Invalid status specified: \"%s\"", status)) + return userAnimeList, e.InvalidStatusError } // get own list if user not specified diff --git a/user/anime/update_animelist.go b/user/anime/update_animelist.go index 8371691..780f079 100644 --- a/user/anime/update_animelist.go +++ b/user/anime/update_animelist.go @@ -17,7 +17,6 @@ package anime 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.IsValidListStatus(status) { - return serverResponse{}, errors.New(fmt.Sprintf("SetStatus: Invalid list status: \"%s\"", status)) + return serverResponse{}, e.InvalidStatusError } // data to be sent to the server @@ -75,7 +74,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 @@ -92,7 +91,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 @@ -109,7 +108,7 @@ func (c Client)SetRewatchValue(id int, rewatchValue int) (serverResponse, error) // checks if specified rewatch value is valid if !e.IsValidRewatchValue(rewatchValue) { - return serverResponse{}, errors.New(fmt.Sprintf("SetRewatchValue: Invalid rewatch value: %d doesn't lie within 0-5", rewatchValue)) + return serverResponse{}, e.InvalidRewatchValueError } // data to be sent to the server @@ -165,22 +164,22 @@ func (c Client)UpdateAnime(id int, data UpdateAnimeData) (serverResponse, error) // checks if specified list status is valid if !e.IsValidListStatus(data.Status) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateAnime: 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("UpdateAnime: 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("UpdateAnime: Invalid priority: %d doesn't lie within 0-2", data.Priority)) + return serverResponse{}, e.InvalidPriorityError } // checks if specified rewatch value is valid if !e.IsValidRewatchValue(data.RewatchValue) { - return serverResponse{}, errors.New(fmt.Sprintf("UpdateAnime: Invalid rewatch value: %d doesn't lie within 0-5", data.RewatchValue)) + return serverResponse{}, e.InvalidRereadValueError } params := url.Values{} 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{} |