diff --git a/internal/games/api_igdb.go b/internal/games/api_igdb.go index 8d47bb1..0a46d33 100644 --- a/internal/games/api_igdb.go +++ b/internal/games/api_igdb.go @@ -187,13 +187,23 @@ func makeRequest(endpoint string, id float64) (string, error) { } // Get the image_id and construct the URL - if len(coverResponse) > 0 { - imageID := coverResponse[0]["image_id"].(string) + if len(coverResponse) == 0 { + return "", fmt.Errorf("no image found for ID %f", id) + } + + if status, exists := coverResponse[0]["status"]; exists { + if status == 400 { + return "", fmt.Errorf("error 400, Syntax error on image: %f", id) + } + } + + if imgID, exists := coverResponse[0]["image_id"]; exists { + imageID := imgID.(string) coverURL := fmt.Sprintf("https://images.igdb.com/igdb/image/upload/t_original/%s.jpg", imageID) return coverURL, nil } + return "", fmt.Errorf("some error happened with image: %s", id) - return "", fmt.Errorf("no image found for ID %d", id) } func DownloadImage(url, slug, suffix string) error {