Make error messages more consistent

This commit is contained in:
iacore
2024-02-24 15:28:11 +00:00
parent a11b1470fa
commit 435567dd97
9 changed files with 25 additions and 25 deletions
+2 -2
View File
@@ -83,13 +83,13 @@ func UnwrapWebAPIRequest(context context.Context, URL, token string) (string, er
return "", errors.New(resp.Message)
}
if !gjson.Valid(resp.Body) {
return "", fmt.Errorf("invalid json: %v", resp.Body)
return "", fmt.Errorf("Invalid JSON: %v", resp.Body)
}
err := gjson.Get(resp.Body, "error")
if !err.Exists() {
return "", errors.New("incompatible request body")
return "", errors.New("Incompatible request body")
}
if err.Bool() {
+2 -2
View File
@@ -23,7 +23,7 @@ func GetDiscoveryArtwork(c *fiber.Ctx, mode string) ([]ArtworkBrief, error) {
}
resp = session.ProxyImageUrl(c, resp)
if !gjson.Valid(resp) {
return nil, fmt.Errorf("invalid json: %v", resp)
return nil, fmt.Errorf("Invalid JSON: %v", resp)
}
data := gjson.Get(resp, "thumbnails.illust").String()
@@ -48,7 +48,7 @@ func GetDiscoveryNovels(c *fiber.Ctx, mode string) ([]NovelBrief, error) {
}
resp = session.ProxyImageUrl(c, resp)
if !gjson.Valid(resp) {
return nil, fmt.Errorf("invalid json: %v", resp)
return nil, fmt.Errorf("Invalid JSON: %v", resp)
}
data := gjson.Get(resp, "thumbnails.novel").String()
+1 -1
View File
@@ -60,7 +60,7 @@ func GetLanding(c *fiber.Ctx, mode string) (*LandingArtworks, error) {
resp = session.ProxyImageUrl(c, resp)
if !gjson.Valid(resp) {
return nil, fmt.Errorf("invalid json: %v", resp)
return nil, fmt.Errorf("Invalid JSON: %v", resp)
}
artworks := map[string]ArtworkBrief{}
+1 -1
View File
@@ -41,7 +41,7 @@ func pixivPostRequest(c *fiber.Ctx, url, payload, token, csrf string) error {
}
body_s := string(body)
if !gjson.Valid(body_s) {
return fmt.Errorf("invalid json: %v", body_s)
return fmt.Errorf("Invalid JSON: %v", body_s)
}
errr := gjson.Get(body_s, "error")
+3 -4
View File
@@ -1,7 +1,6 @@
package pages
import (
"errors"
"fmt"
"strconv"
"strings"
@@ -12,8 +11,8 @@ import (
)
func ArtworkMultiPage(c *fiber.Ctx) error {
param_ids := c.Params("ids")
ids := strings.Split(param_ids, ",")
ids_ := c.Params("ids")
ids := strings.Split(ids_, ",")
artworks := make([]*core.Illust, len(ids))
@@ -21,7 +20,7 @@ func ArtworkMultiPage(c *fiber.Ctx) error {
wg.Add(len(ids))
for i, id := range ids {
if _, err := strconv.Atoi(id); err != nil {
return errors.New("invalid id")
return fmt.Errorf("Invalid ID: %s", id)
}
go func(i int, id string) {
+9 -9
View File
@@ -1,7 +1,7 @@
package pages
import (
"errors"
"fmt"
"strconv"
core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
@@ -9,12 +9,12 @@ import (
)
func ArtworkPage(c *fiber.Ctx) error {
param_id := c.Params("id")
if _, err := strconv.Atoi(param_id); err != nil {
return errors.New("invalid id")
id := c.Params("id")
if _, err := strconv.Atoi(id); err != nil {
return fmt.Errorf("Invalid ID: %s", id)
}
illust, err := core.GetArtworkByID(c, param_id, true)
illust, err := core.GetArtworkByID(c, id, true)
if err != nil {
return err
}
@@ -34,12 +34,12 @@ func ArtworkPage(c *fiber.Ctx) error {
}
func ArtworkEmbedPage(c *fiber.Ctx) error {
param_id := c.Params("id")
if _, err := strconv.Atoi(param_id); err != nil {
return errors.New("invalid id")
id := c.Params("id")
if _, err := strconv.Atoi(id); err != nil {
return fmt.Errorf("Invalid ID: %s", id)
}
illust, err := core.GetArtworkByID(c, param_id, false)
illust, err := core.GetArtworkByID(c, id, false)
if err != nil {
return err
}
+5 -5
View File
@@ -1,7 +1,7 @@
package pages
import (
"errors"
"fmt"
"strconv"
core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
@@ -9,12 +9,12 @@ import (
)
func NovelPage(c *fiber.Ctx) error {
param_id := c.Params("id")
if _, err := strconv.Atoi(param_id); err != nil {
return errors.New("invalid id")
id := c.Params("id")
if _, err := strconv.Atoi(id); err != nil {
return fmt.Errorf("Invalid ID: %s", id)
}
novel, err := core.GetNovelByID(c, param_id)
novel, err := core.GetNovelByID(c, id)
if err != nil {
return err
}
+1 -1
View File
@@ -116,7 +116,7 @@ func SettingsPost(c *fiber.Ctx) error {
case "reset-all":
err = resetAll(c)
default:
err = errors.New("no such setting available")
err = errors.New("No such setting is available.")
}
if err != nil {
+1
View File
@@ -0,0 +1 @@
checks = ["inherit", "-ST1005"] # no "error strings should not be capitalized"