From 37453ddfda7950b9b4425475a08bd8281e652642 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 7 Jul 2026 20:56:34 +0000 Subject: [PATCH] =?UTF-8?q?Return=20200+null=20instead=20of=20404=20when?= =?UTF-8?q?=20no=20cash=20up=20found=20for=20date=20=E2=80=94=20eliminates?= =?UTF-8?q?=20browser=20console=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/cashup.js | 2 +- frontend/src/pages/DailyCashUp.tsx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/routes/cashup.js b/backend/src/routes/cashup.js index fc71bb1..06f357d 100644 --- a/backend/src/routes/cashup.js +++ b/backend/src/routes/cashup.js @@ -12,7 +12,7 @@ export async function cashupRoutes(app) { const { rows } = await pool.query( 'SELECT * FROM cash_ups WHERE session_date = $1', [date] ) - if (!rows.length) return reply.status(404).send({ error: 'Not found' }) + if (!rows.length) return { cash_up: null } const cashUp = rows[0] const [denoms, machines, recon, attachments] = await Promise.all([ diff --git a/frontend/src/pages/DailyCashUp.tsx b/frontend/src/pages/DailyCashUp.tsx index 07b5f4a..8a1845d 100644 --- a/frontend/src/pages/DailyCashUp.tsx +++ b/frontend/src/pages/DailyCashUp.tsx @@ -177,14 +177,14 @@ export function DailyCashUp({ user }: Props) { setCheckedItems(new Set()) api.get<{ - cash_up: CashUp; denominations: Denomination[]; card_machines: CardMachine[]; + cash_up: CashUp | null; denominations: Denomination[]; card_machines: CardMachine[]; reconciliation: ReconciliationRow[]; attachments: Attachment[] }>(`/cashup?date=${date}`) - .then(data => applyLoaded(data)) - .catch(e => { - if (e instanceof Error && e.message === 'Not found') setPageState('empty') - else { flash('Failed to load data for this date.', false); setPageState('empty') } + .then(data => { + if (!data.cash_up) { setPageState('empty'); return } + applyLoaded(data as { cash_up: CashUp; denominations: Denomination[]; card_machines: CardMachine[]; attachments: Attachment[] }) }) + .catch(() => { flash('Failed to load data for this date.', false); setPageState('empty') }) // Auto-fetch Newbook — soft failure, user can retry with the button api.post<{ count: number; totals: PaymentTotals; till_payments: TillPayment[]; transaction_breakdown: TransactionBreakdown }>(