Imp errors

This commit is contained in:
Óscar M. Lage 2024-12-17 14:31:16 +01:00
parent 0929e681ce
commit 8461747d02

View File

@ -187,13 +187,23 @@ func makeRequest(endpoint string, id float64) (string, error) {
} }
// Get the image_id and construct the URL // Get the image_id and construct the URL
if len(coverResponse) > 0 { if len(coverResponse) == 0 {
imageID := coverResponse[0]["image_id"].(string) 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) coverURL := fmt.Sprintf("https://images.igdb.com/igdb/image/upload/t_original/%s.jpg", imageID)
return coverURL, nil 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 { func DownloadImage(url, slug, suffix string) error {