refactor: use errors.New for static error strings
This commit is contained in:
@@ -2,7 +2,7 @@ package allanime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"mal/internal/domain"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -48,17 +48,17 @@ func (c *AllAnimeProvider) GetAvailableEpisodes(ctx context.Context, showID stri
|
||||
|
||||
data, ok := result["data"].(map[string]any)
|
||||
if !ok {
|
||||
return AvailableEpisodes{}, fmt.Errorf("invalid response")
|
||||
return AvailableEpisodes{}, errors.New("invalid response")
|
||||
}
|
||||
|
||||
show, ok := data["show"].(map[string]any)
|
||||
if !ok || show == nil {
|
||||
return AvailableEpisodes{}, fmt.Errorf("show not found")
|
||||
return AvailableEpisodes{}, errors.New("show not found")
|
||||
}
|
||||
|
||||
detail, ok := show["availableEpisodesDetail"].(map[string]any)
|
||||
if !ok {
|
||||
return AvailableEpisodes{}, fmt.Errorf("invalid detail")
|
||||
return AvailableEpisodes{}, errors.New("invalid detail")
|
||||
}
|
||||
|
||||
return AvailableEpisodes{
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
||||
}
|
||||
|
||||
if len(raw) < 29 {
|
||||
return nil, fmt.Errorf("encrypted payload too short")
|
||||
return nil, errors.New("encrypted payload too short")
|
||||
}
|
||||
|
||||
version := raw[0]
|
||||
@@ -54,7 +55,7 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("decryption failed")
|
||||
return nil, errors.New("decryption failed")
|
||||
}
|
||||
|
||||
func tryDecryptCTR(block cipher.Block, iv []byte, cipherText []byte) []byte {
|
||||
|
||||
@@ -2,6 +2,7 @@ package allanime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -41,28 +42,28 @@ func (c *AllAnimeProvider) GetEpisodeSources(ctx context.Context, showID string,
|
||||
|
||||
data, ok := result["data"].(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid source response")
|
||||
return nil, errors.New("invalid source response")
|
||||
}
|
||||
|
||||
rawSourceURLs, ok := data["episode"].(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid episode response")
|
||||
return nil, errors.New("invalid episode response")
|
||||
}
|
||||
|
||||
sourceURLs, ok := rawSourceURLs["sourceUrls"].([]any)
|
||||
if !ok || len(sourceURLs) == 0 {
|
||||
return nil, fmt.Errorf("no source urls")
|
||||
return nil, errors.New("no source urls")
|
||||
}
|
||||
|
||||
references := buildSourceReferences(sourceURLs)
|
||||
if len(references) == 0 {
|
||||
return nil, fmt.Errorf("no source references")
|
||||
return nil, errors.New("no source references")
|
||||
}
|
||||
|
||||
out := c.resolveSourceReferences(ctx, references)
|
||||
|
||||
if len(out) == 0 {
|
||||
return nil, fmt.Errorf("no playable sources extracted")
|
||||
return nil, errors.New("no playable sources extracted")
|
||||
}
|
||||
|
||||
return out, nil
|
||||
@@ -261,7 +262,7 @@ func (c *AllAnimeProvider) graphqlRequestWithHash(ctx context.Context, showID, e
|
||||
|
||||
data, ok := parsed["data"].(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no data in response")
|
||||
return nil, errors.New("no data in response")
|
||||
}
|
||||
|
||||
decrypted, err := responseFromTobeparsed(data)
|
||||
@@ -276,7 +277,7 @@ func (c *AllAnimeProvider) graphqlRequestWithHash(ctx context.Context, showID, e
|
||||
return parsed, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no usable data in response")
|
||||
return nil, errors.New("no usable data in response")
|
||||
}
|
||||
|
||||
func newEpisodeHashRequest(ctx context.Context, showID, episode, mode string) (*http.Request, error) {
|
||||
|
||||
Reference in New Issue
Block a user