aboutsummaryrefslogtreecommitdiff
path: root/errhandlers
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-03-06 00:51:36 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-03-06 00:51:36 +0530
commitb6f42d806d0e0f5e59c7615cd1558e75c5b314f1 (patch)
treec9c014759f62c44520be305a60546d08140876f4 /errhandlers
parent95b8ab702708538ccaf26efd141b448148ac6d6d (diff)
Exported all the errors so programs using this library can customize error messages.
Diffstat (limited to 'errhandlers')
-rw-r--r--errhandlers/errhandlers.go15
-rw-r--r--errhandlers/errors.go38
2 files changed, 48 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
diff --git a/errhandlers/errors.go b/errhandlers/errors.go
new file mode 100644
index 0000000..4ea4311
--- /dev/null
+++ b/errhandlers/errors.go
@@ -0,0 +1,38 @@
+/* MAL2Go - MyAnimeList V2 API wrapper for Go
+ * Copyright (C) 2022 Vidhu Kant Sharma <vidhukant@protonmail.ch>
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+package errhandlers
+
+import (
+ "errors"
+)
+
+var InvalidFieldError error = errors.New("InvalidFieldError: Invalid field specified.")
+var InvalidLimitError error = errors.New("InvalidLimitError: Limit specified too high.")
+var InvalidLimitError500 error = errors.New("InvalidLimitError: Limit specified too high. (max is 500)")
+var InvalidLimitError1000 error = errors.New("InvalidLimitError: Limit specified too high. (max is 1000)")
+
+var InvalidRankingError error = errors.New("InvalidRankingError: Invalid ranking type specified.")
+var InvalidSeasonError error = errors.New("InvalidSeasonError: Invalid season specifield.")
+var InvalidSortError error = errors.New("InvalidSortError: Invalid sort type specifield.")
+var InvalidStatusError error = errors.New("InvalidStatusError: Invalid status specified.")
+
+var URLNameValueError error = errors.New("URLNameValueError: Number of names and values passed to URLGenerator don't match.")
+
+var InvalidScoreError error = errors.New("InvalidScoreError: Score should lie between 0-10.")
+var InvalidPriorityError error = errors.New("InvalidPriorityError: Priority should lie between 0-2.")
+var InvalidRewatchValueError error = errors.New("InvalidRewatchValueError: Rewatch value should lie between 0-5.")
+var InvalidRereadValueError error = errors.New("InvalidRereadValueError: Reread value should lie between 0-5.")