From 26226e822e8c4d7c1bf341db957ad8ed7d6528cc Mon Sep 17 00:00:00 2001 From: hamed-zeidabadi Date: Fri, 7 Nov 2025 19:55:05 +0330 Subject: [PATCH] fix: add error handling to deleteInvoice action Add try-catch block to deleteInvoice function to properly handle database errors. This ensures consistent error handling across all CRUD operations and prevents unhandled promise rejections when database operations fail. Changes: - Wrap database operation in try-catch block - Return error message on failure - Return success message on completion --- dashboard/final-example/app/lib/actions.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dashboard/final-example/app/lib/actions.ts b/dashboard/final-example/app/lib/actions.ts index b047a645..2538da0a 100644 --- a/dashboard/final-example/app/lib/actions.ts +++ b/dashboard/final-example/app/lib/actions.ts @@ -110,8 +110,13 @@ export async function updateInvoice( } export async function deleteInvoice(id: string) { - await sql`DELETE FROM invoices WHERE id = ${id}`; - revalidatePath('/dashboard/invoices'); + try { + await sql`DELETE FROM invoices WHERE id = ${id}`; + revalidatePath('/dashboard/invoices'); + return { message: 'Deleted Invoice.' }; + } catch (error) { + return { message: 'Database Error: Failed to Delete Invoice.' }; + } } export async function authenticate(