From 8461747d022f1483daa1b663e8300538c8f899f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Tue, 17 Dec 2024 14:31:16 +0100 Subject: [PATCH] Imp errors --- internal/games/api_igdb.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 {