refactor(product page, api): improve error handling and enhance type safety
- Refactored error handling in the product page to simplify catch block. - Updated type definitions in openFoodFactsApi for better type safety. - Introduced utility functions for search type detection and barcode validation.
This commit is contained in:
1 parent
f98c648311
commit
c99c82c837
2 files changed
+30
-14
No files matched your search
@@ -3,22 +3,22 @@
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import {
|
||||
ArrowLeft, AlertCircle, AlertTriangle,
|
||||
Database, Globe, ShieldCheck, Beaker, ClipboardList
|
||||
import {
|
||||
ArrowLeft,
|
||||
AlertCircle,
|
||||
AlertTriangle,
|
||||
Database,
|
||||
Globe,
|
||||
ShieldCheck,
|
||||
Beaker,
|
||||
ClipboardList,
|
||||
} from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Image from "next/image";
|
||||
import {
|
||||
searchByBarcode,
|
||||
Product,
|
||||
formatNutritionData,
|
||||
} from "@/lib/openFoodFactsApi";
|
||||
import Link from "next/link";
|
||||
import { searchByBarcode, Product, formatNutritionData } from "@/lib/openFoodFactsApi";
|
||||
import { NutriScoreBadge, NovaBadge } from "@/app/components/NutriScoreBadge";
|
||||
import { NutritionGrid } from "@/app/components/NutritionBar";
|
||||
import { ProductSkeleton } from "@/app/components/ProductSkeleton";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export default function ProdutoPage() {
|
||||
const params = useParams();
|
||||
@@ -36,7 +36,7 @@ export default function ProdutoPage() {
|
||||
const result = await searchByBarcode(barcode);
|
||||
if (result) setProduct(result);
|
||||
else setError("Produto não catalogado na base ODbL.");
|
||||
} catch (err) {
|
||||
} catch {
|
||||
setError("Falha crítica na sincronização de dados.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in new issue
Block a user