🐛 Add Debug Logging for Thumbnails API Error
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.
This commit is contained in:
parent
00e3a3a902
commit
2951efdaa0
1 changed files with 17 additions and 0 deletions
|
|
@ -34,9 +34,12 @@ export default async function handler(req, res) {
|
||||||
// Determine if identifier is a slug or numeric ID
|
// Determine if identifier is a slug or numeric ID
|
||||||
const isSlug = isValidSlug(identifier) || isNaN(parseInt(identifier));
|
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
|
// Verify user has access to this collection
|
||||||
let collectionResult;
|
let collectionResult;
|
||||||
if (isSlug) {
|
if (isSlug) {
|
||||||
|
console.log('🔍 Querying by slug:', identifier);
|
||||||
collectionResult = await sql`
|
collectionResult = await sql`
|
||||||
SELECT c.*, cp.role as user_role
|
SELECT c.*, cp.role as user_role
|
||||||
FROM collections c
|
FROM collections c
|
||||||
|
|
@ -50,6 +53,7 @@ export default async function handler(req, res) {
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
const numericId = parseInt(identifier);
|
const numericId = parseInt(identifier);
|
||||||
|
console.log('🔍 Querying by ID:', numericId);
|
||||||
collectionResult = await sql`
|
collectionResult = await sql`
|
||||||
SELECT c.*, cp.role as user_role
|
SELECT c.*, cp.role as user_role
|
||||||
FROM collections c
|
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' });
|
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];
|
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
|
// Get the top 5 rarest cards from the collection
|
||||||
const thumbnailsResult = await sql`
|
const thumbnailsResult = await sql`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue