Compare commits

..

No commits in common. "main" and "v1.5.1" have entirely different histories.
main ... v1.5.1

4 changed files with 1 additions and 38 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
api_test.go

4
api.go
View File

@ -49,10 +49,6 @@ func request[T any](api *Api, query string, vars map[string]interface{}, respObj
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return handleError(resp)
}
//data, _ := ioutil.ReadAll(resp.Body)
//fmt.Println(string(data))

View File

@ -1,32 +0,0 @@
package anilist
import (
"encoding/json"
"errors"
"net/http"
)
type apiError struct {
Message string `json:"message"`
Status int `json:"status"`
}
type apiErrResp struct {
Errors []apiError `json:"errors"`
}
func handleError(resp *http.Response) error {
respObj := &apiErrResp{}
dec := json.NewDecoder(resp.Body)
err := dec.Decode(respObj)
if err != nil {
return err
}
if len(respObj.Errors) == 0 {
return errors.New("unknown API error")
}
return errors.New(respObj.Errors[0].Message)
}

View File

@ -18,7 +18,7 @@ func addValue2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value T)
}
func addSlice2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value []T) {
if len(value) > 0 {
if value != nil && len(value) > 0 {
m[key] = value
}
}