From 650a1bb55c34b543b51e6fc4cb7a336cbe06600d Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Fri, 10 Apr 2026 17:59:34 +0200 Subject: [PATCH] Add error handling for missing recipe ID in EditRecipePage --- frontend/app/recipes/[id]/edit/page.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/app/recipes/[id]/edit/page.tsx b/frontend/app/recipes/[id]/edit/page.tsx index 088a4f4a..cfbe26d8 100644 --- a/frontend/app/recipes/[id]/edit/page.tsx +++ b/frontend/app/recipes/[id]/edit/page.tsx @@ -8,7 +8,7 @@ import type { Product, Recipe } from '../../../../features/inventory/types'; export default function EditRecipePage() { const router = useRouter(); const params = useParams(); - const recipeId = Array.isArray(params.id) ? params.id[0] : params.id; + const recipeId = params && (Array.isArray(params.id) ? params.id[0] : params.id); const [recipe, setRecipe] = useState({ name: '', @@ -23,6 +23,12 @@ export default function EditRecipePage() { useEffect(() => { const loadData = async () => { + if (!recipeId) { + setError('Receptet hittades inte.'); + setIsLoading(false); + return; + } + try { // Ladda produkter const productsData = await fetchJson('/api/products');