From e21dc47f2fe1dd3b1ad47224cd9cc3e75d0835fb Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 23 Feb 2022 21:32:44 +0530 Subject: finalized manga package with all the endpoints added --- errhandlers/errhandlers.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'errhandlers/errhandlers.go') diff --git a/errhandlers/errhandlers.go b/errhandlers/errhandlers.go index 14c1d33..5f4db25 100644 --- a/errhandlers/errhandlers.go +++ b/errhandlers/errhandlers.go @@ -22,8 +22,9 @@ import ( "github.com/MikunoNaka/MAL2Go/util" ) -// if fields aren't specified +// this is only for anime fields func FieldsErrHandler(fields []string) ([]string, error) { + // if fields aren't specified if cap(fields) == 0 { // uses all the default fields if none specified return util.DefaultFields, nil @@ -40,6 +41,25 @@ func FieldsErrHandler(fields []string) ([]string, error) { return fields, nil } +// only for manga fields +func MangaFieldsErrHandler(fields []string) ([]string, error) { + // if fields aren't specified + if cap(fields) == 0 { + // uses all the default fields if none specified + return util.DefaultMangaFields, nil + } + + // 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)) + } + } + + // everything's fine! + return fields, nil +} + // if limit or error specified are above the limit func LimitErrHandler(limit, maxLimit int) error { if limit > maxLimit { -- cgit v1.2.3