From bd44b366660e7e7405ec5ca619f62566b3a1c19a Mon Sep 17 00:00:00 2001 From: Crumb Owl Date: Mon, 14 Jul 2025 21:45:18 +0000 Subject: [PATCH] ProductBarcode: BarcodeModal: improve erroring --- frontend/components/Item/BarcodeModal.vue | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/frontend/components/Item/BarcodeModal.vue b/frontend/components/Item/BarcodeModal.vue index a31e462b..571702ac 100644 --- a/frontend/components/Item/BarcodeModal.vue +++ b/frontend/components/Item/BarcodeModal.vue @@ -5,6 +5,15 @@ {{ $t("components.item.product_import.title") }} + +
(""); const products = ref(null); const selectedRow = ref(-1); + const errorMessage = ref(null); type BarcodeTableHeader = { text: string; @@ -139,6 +150,7 @@ registerOpenDialogCallback(DialogID.ProductImport, params => { selectedRow.value = -1; searching.value = false; + errorMessage.value = null; if (params?.barcode) { // Reset if the barcode is different @@ -166,8 +178,11 @@ } async function retrieveProductInfo(barcode: string) { - if (!barcode || barcode.trim().length === 0) { - console.error("Invalid barcode provided"); + errorMessage.value = null; + + if (!barcode || barcode.trim().length === 0 || !(/^[0-9]+$/.test(barcode))) { + errorMessage.value = "Invalid barcode provided"; + console.error(errorMessage.value); return; } @@ -177,12 +192,14 @@ try { const result = await api.products.searchFromBarcode(barcode.trim()); if (result.error) { - console.error("API Error:", result.error); + errorMessage.value = "API Error: " + result.error; + console.error(errorMessage.value); } else { products.value = result.data; } } catch (error) { - console.error("Failed to retrieve product info:", error); + errorMessage.value = "Failed to retrieve product info: " + error; + console.error(errorMessage.value); } finally { searching.value = false; }