Return 200+null instead of 404 when no cash up found for date — eliminates browser console error

This commit is contained in:
jtricerolph 2026-07-07 20:56:34 +00:00
parent ed9cce1d76
commit 37453ddfda
2 changed files with 6 additions and 6 deletions

View file

@ -12,7 +12,7 @@ export async function cashupRoutes(app) {
const { rows } = await pool.query( const { rows } = await pool.query(
'SELECT * FROM cash_ups WHERE session_date = $1', [date] '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 cashUp = rows[0]
const [denoms, machines, recon, attachments] = await Promise.all([ const [denoms, machines, recon, attachments] = await Promise.all([

View file

@ -177,14 +177,14 @@ export function DailyCashUp({ user }: Props) {
setCheckedItems(new Set()) setCheckedItems(new Set())
api.get<{ api.get<{
cash_up: CashUp; denominations: Denomination[]; card_machines: CardMachine[]; cash_up: CashUp | null; denominations: Denomination[]; card_machines: CardMachine[];
reconciliation: ReconciliationRow[]; attachments: Attachment[] reconciliation: ReconciliationRow[]; attachments: Attachment[]
}>(`/cashup?date=${date}`) }>(`/cashup?date=${date}`)
.then(data => applyLoaded(data)) .then(data => {
.catch(e => { if (!data.cash_up) { setPageState('empty'); return }
if (e instanceof Error && e.message === 'Not found') setPageState('empty') applyLoaded(data as { cash_up: CashUp; denominations: Denomination[]; card_machines: CardMachine[]; attachments: Attachment[] })
else { flash('Failed to load data for this date.', false); setPageState('empty') }
}) })
.catch(() => { flash('Failed to load data for this date.', false); setPageState('empty') })
// Auto-fetch Newbook — soft failure, user can retry with the button // Auto-fetch Newbook — soft failure, user can retry with the button
api.post<{ count: number; totals: PaymentTotals; till_payments: TillPayment[]; transaction_breakdown: TransactionBreakdown }>( api.post<{ count: number; totals: PaymentTotals; till_payments: TillPayment[]; transaction_breakdown: TransactionBreakdown }>(