added check for 403 in get anilist watchlist
This commit is contained in:
		@@ -360,27 +360,47 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	returnedBody, _ := AniListQuery(body, true)
 | 
						returnedBody, status := AniListQuery(body, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var badPost struct {
 | 
				
			||||||
 | 
							Errors []struct {
 | 
				
			||||||
 | 
								Message   string `json:"message"`
 | 
				
			||||||
 | 
								Status    int    `json:"status"`
 | 
				
			||||||
 | 
								Locations []struct {
 | 
				
			||||||
 | 
									Line   int `json:"line"`
 | 
				
			||||||
 | 
									Column int `json:"column"`
 | 
				
			||||||
 | 
								} `json:"locations"`
 | 
				
			||||||
 | 
							} `json:"errors"`
 | 
				
			||||||
 | 
							Data any `json:"data"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	var post AniListCurrentUserWatchList
 | 
						var post AniListCurrentUserWatchList
 | 
				
			||||||
	err := json.Unmarshal(returnedBody, &post)
 | 
						if status == "200 OK" {
 | 
				
			||||||
	if err != nil {
 | 
							err := json.Unmarshal(returnedBody, &post)
 | 
				
			||||||
		log.Printf("Failed at unmarshal, %s\n", err)
 | 
							if err != nil {
 | 
				
			||||||
	}
 | 
								log.Printf("Failed at unmarshal, %s\n", err)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Getting the real total, finding the real last page and storing that in the Page info
 | 
					 | 
				
			||||||
	statuses := post.Data.Page.MediaList[0].User.Statistics.Anime.Statuses
 | 
					 | 
				
			||||||
	var total int
 | 
					 | 
				
			||||||
	for _, status := range statuses {
 | 
					 | 
				
			||||||
		if status.Status == "CURRENT" {
 | 
					 | 
				
			||||||
			total = status.Count
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// Getting the real total, finding the real last page and storing that in the Page info
 | 
				
			||||||
 | 
							statuses := post.Data.Page.MediaList[0].User.Statistics.Anime.Statuses
 | 
				
			||||||
 | 
							var total int
 | 
				
			||||||
 | 
							for _, status := range statuses {
 | 
				
			||||||
 | 
								if status.Status == "CURRENT" {
 | 
				
			||||||
 | 
									total = status.Count
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lastPage := total / perPage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							post.Data.Page.PageInfo.Total = total
 | 
				
			||||||
 | 
							post.Data.Page.PageInfo.LastPage = lastPage
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lastPage := total / perPage
 | 
						if status == "403 Forbidden" {
 | 
				
			||||||
 | 
							err := json.Unmarshal(returnedBody, &badPost)
 | 
				
			||||||
	post.Data.Page.PageInfo.Total = total
 | 
							if err != nil {
 | 
				
			||||||
	post.Data.Page.PageInfo.LastPage = lastPage
 | 
								log.Printf("Failed at unmarshal, %s\n", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							log.Fatal(badPost.Errors[0].Message)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return post
 | 
						return post
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user