diff --git a/utils/visionUtils.ts b/utils/visionUtils.ts index d1d84f0..af2801d 100644 --- a/utils/visionUtils.ts +++ b/utils/visionUtils.ts @@ -28,15 +28,15 @@ export const scanProduct = async (imageData: string): Promise<{ name: string; qu if (specificLabels.length > 0) { // Use the most confident specific label - const productName = specificLabels[0].description; + const productName = specificLabels[0]?.description || 'Unknown Product'; // Log all labels for debugging - console.log('All labels:', labels.map(l => `${l.description} (${l.score})`).join(', ')); + console.log('All labels:', labels.map(l => `${l.description || 'Unknown'} (${l.score || 'N/A'})`).join(', ')); return { name: productName, quantity: 1, allLabels: labels.map(label => label.description || '').filter(Boolean) }; } else if (labels.length > 0) { // If no specific labels, use the most confident general label - const productName = labels[0].description; + const productName = labels[0]?.description || 'Unknown Product'; return { name: productName, quantity: 1, allLabels: labels.map(label => label.description || '').filter(Boolean) }; } else { throw new Error('No labels detected in the image');