From d4fc0f1fee370e1a073c0685b141303d5fce48e9 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 16 Mar 2026 11:31:19 +0100 Subject: [PATCH] fix(slots) : check API response before updating local state on slot selection The save functions (savePieceSlotSelection, saveProductSlotSelection, saveSubcomponentSlotSelection) were not checking result.success before updating local state and showing success toast. Since useApi.patch() never throws, the catch block was dead code and errors were silently ignored while the UI showed success. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/composables/useComponentEdit.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/app/composables/useComponentEdit.ts b/app/composables/useComponentEdit.ts index 36b0972..1f8ec31 100644 --- a/app/composables/useComponentEdit.ts +++ b/app/composables/useComponentEdit.ts @@ -313,9 +313,8 @@ export function useComponentEdit(componentId: string) { }) const savePieceSlotSelection = async (slotId: string, selectedPieceId: string | null) => { - try { - await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId }) - // Update local structure + const result = await patch(`/composant-piece-slots/${slotId}`, { selectedPieceId }) + if (result.success) { const structure = component.value?.structure if (structure?.pieces) { const slot = (structure.pieces as any[]).find((s: any) => s.slotId === slotId) @@ -323,14 +322,11 @@ export function useComponentEdit(componentId: string) { } toast.showSuccess('Pièce mise à jour') } - catch (error: any) { - toast.showError(error?.message || 'Erreur lors de la mise à jour') - } } const saveProductSlotSelection = async (slotId: string, selectedProductId: string | null) => { - try { - await patch(`/composant-product-slots/${slotId}`, { selectedProductId }) + const result = await patch(`/composant-product-slots/${slotId}`, { selectedProductId }) + if (result.success) { const structure = component.value?.structure if (structure?.products) { const slot = (structure.products as any[]).find((s: any) => s.slotId === slotId) @@ -338,14 +334,11 @@ export function useComponentEdit(componentId: string) { } toast.showSuccess('Produit mis à jour') } - catch (error: any) { - toast.showError(error?.message || 'Erreur lors de la mise à jour') - } } const saveSubcomponentSlotSelection = async (slotId: string, selectedComposantId: string | null) => { - try { - await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId }) + const result = await patch(`/composant-subcomponent-slots/${slotId}`, { selectedComposantId }) + if (result.success) { const structure = component.value?.structure if (structure?.subcomponents) { const slot = (structure.subcomponents as any[]).find((s: any) => s.slotId === slotId) @@ -353,9 +346,6 @@ export function useComponentEdit(componentId: string) { } toast.showSuccess('Sous-composant mis à jour') } - catch (error: any) { - toast.showError(error?.message || 'Erreur lors de la mise à jour') - } } const saveSlotQuantity = async (entry: SelectionEntry) => {