From 2951efdaa00d8f1a397bbb9f8f681fd3de3f2a77 Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Sun, 27 Jul 2025 14:11:51 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20Debug=20Logging=20for=20Th?= =?UTF-8?q?umbnails=20API=20Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added comprehensive debugging to identify why collection.id is undefined: - Log identifier analysis (slug vs ID detection) - Log which query path is taken (slug vs numeric ID) - Log collection result structure and content - Add validation for collection data before using collection.id - Better error messages for debugging This will help identify the root cause of the thumbnails API failure. --- .../api/collections/[identifier]/thumbnails.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pages/api/collections/[identifier]/thumbnails.js b/pages/api/collections/[identifier]/thumbnails.js index a6d08f9..163ab8e 100644 --- a/pages/api/collections/[identifier]/thumbnails.js +++ b/pages/api/collections/[identifier]/thumbnails.js @@ -34,9 +34,12 @@ export default async function handler(req, res) { // Determine if identifier is a slug or numeric ID const isSlug = isValidSlug(identifier) || isNaN(parseInt(identifier)); + console.log('🔍 Identifier analysis:', { identifier, isSlug, isValidSlug: isValidSlug(identifier), isNaN: isNaN(parseInt(identifier)) }); + // Verify user has access to this collection let collectionResult; if (isSlug) { + console.log('🔍 Querying by slug:', identifier); collectionResult = await sql` SELECT c.*, cp.role as user_role FROM collections c @@ -50,6 +53,7 @@ export default async function handler(req, res) { `; } else { const numericId = parseInt(identifier); + console.log('🔍 Querying by ID:', numericId); collectionResult = await sql` SELECT c.*, cp.role as user_role FROM collections c @@ -67,7 +71,20 @@ export default async function handler(req, res) { return res.status(404).json({ error: 'Collection not found or access denied' }); } + console.log('🔍 Collection result:', { + identifier, + isSlug, + resultLength: collectionResult.length, + collection: collectionResult[0] + }); + const collection = collectionResult[0]; + + // Add debugging and validation + if (!collection || !collection.id) { + console.error('Collection data invalid:', { collection, identifier, isSlug }); + return res.status(500).json({ error: 'Collection data invalid' }); + } // Get the top 5 rarest cards from the collection const thumbnailsResult = await sql`