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 /errhandlers/errhandlers.go | |
parent | 95b8ab702708538ccaf26efd141b448148ac6d6d (diff) |
Exported all the errors so programs using this library can customize error messages.
Diffstat (limited to 'errhandlers/errhandlers.go')
-rw-r--r-- | errhandlers/errhandlers.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/errhandlers/errhandlers.go b/errhandlers/errhandlers.go index 5f4db25..dd5f9f8 100644 --- a/errhandlers/errhandlers.go +++ b/errhandlers/errhandlers.go @@ -17,8 +17,6 @@ package errhandlers import ( - "errors" - "fmt" "github.com/MikunoNaka/MAL2Go/util" ) @@ -33,7 +31,7 @@ func FieldsErrHandler(fields []string) ([]string, error) { // checks if each given field is valid for _, j := range(fields) { if !IsValidField(j) { - return []string{}, errors.New(fmt.Sprintf("InvalidFieldError: Invalid field specified: \"%s\"", j)) + return []string{}, InvalidFieldError } } @@ -52,7 +50,7 @@ func MangaFieldsErrHandler(fields []string) ([]string, error) { // checks if each given field is valid for _, j := range(fields) { if !IsValidMangaField(j) { - return []string{}, errors.New(fmt.Sprintf("InvalidFieldError: Invalid field specified: \"%s\"", j)) + return []string{}, InvalidFieldError } } @@ -63,7 +61,14 @@ func MangaFieldsErrHandler(fields []string) ([]string, error) { // if limit or error specified are above the limit func LimitErrHandler(limit, maxLimit int) error { if limit > maxLimit { - return errors.New(fmt.Sprintf("InvalidLimitError: Limit specified too high (%d > %d).", limit, maxLimit)) + switch maxLimit { + case 500: + return InvalidLimitError500 + case 1000: + return InvalidLimitError500 + default: + return InvalidLimitError + } } // return nil if no error return nil |