diff --git a/AniListFunctions.go b/AniListFunctions.go index e7c9340..a04cffe 100644 --- a/AniListFunctions.go +++ b/AniListFunctions.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "fmt" "io" "log" "net/http" @@ -183,7 +184,7 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime { return post } -func (a *App) AniListSearch(query string) any { +func (a *App) AniListSearch(query string) (interface{}, error) { type Variables struct { Search string `json:"search"` ListType string `json:"listType"` @@ -242,18 +243,20 @@ func (a *App) AniListSearch(query string) any { ListType: "ANIME", }, } - returnedBody, _ := AniListQuery(body, false) - + returnedBody, status := AniListQuery(body, false) + if status != "200 OK" { + return nil, fmt.Errorf("API search failed with status: %s", status) + } var post interface{} err := json.Unmarshal(returnedBody, &post) if err != nil { log.Printf("Failed at unmarshal, %s\n", err) + return nil, fmt.Errorf("Failed to parse search results") } - - return post + return post, nil } -func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) AniListCurrentUserWatchList { +func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) (AniListCurrentUserWatchList, error) { user := a.GetAniListLoggedInUser() type Variables struct { Page int `json:"page"` @@ -404,11 +407,15 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani err := json.Unmarshal(returnedBody, &badPost) if err != nil { log.Printf("Failed at unmarshal, %s\n", err) + return post, fmt.Errorf("API authentication error") } - log.Fatal(badPost.Errors[0].Message) + return post, fmt.Errorf("AniList API error: %s", badPost.Errors[0].Message) + } + if status != "200 OK" { + return post, fmt.Errorf("API request failed with status: %s", status) } - return post + return post, nil } func (a *App) AniListUpdateEntry(updateBody AniListUpdateVariables) AniListGetSingleAnime { diff --git a/wails.json b/wails.json index b569037..a0d8223 100644 --- a/wails.json +++ b/wails.json @@ -12,6 +12,6 @@ }, "info": { "productName": "AniTrack", - "productVersion": "0.6.5" + "productVersion": "0.7.0" } }