implement error handling

This commit is contained in:
Michi 2025-04-21 11:27:08 +02:00
parent 39005d46a5
commit 7d2dea886c
5 changed files with 144 additions and 8 deletions

View file

@ -27,10 +27,14 @@ export async function createInvoice(formData: FormData){
const amountInCents = amount * 100;
const date = new Date().toISOString().split('T')[0];
await sql`
INSERT INTO invoices (customer_Id, amount, status, date)
VALUES (${customerId}, ${amountInCents}, ${status}, ${date})
`;
try{
await sql`
INSERT INTO invoices (customer_Id, amount, status, date)
VALUES (${customerId}, ${amountInCents}, ${status}, ${date})
`;
} catch(error){
console.error(error);
}
revalidatePath('/dashboard/invoices');
redirect('/dashboard/invoices');
@ -46,17 +50,27 @@ export async function updateInvoice(id: string, formData: FormData){
});
const amountInCents = amount * 100;
await sql`
try{
await sql`
UPDATE invoices
SET customer_id = ${customerId}, amount = ${amountInCents}, status = ${status}
WHERE id = ${id}
`;
`;
} catch(error){
console.error(error);
}
revalidatePath('/dashboard/invoices');
redirect('/dashboard/invoices');
}
export async function deleteInvoice(id: string){
await sql`DELETE FROM invoices WHERE id = ${id}`;
export async function deleteInvoice(id: string){
try{
await sql`DELETE FROM invoices WHERE id = ${id}`;
} catch (error){
console.error(error);
}
revalidatePath('/dashboard/invoices');
}