mirror of
https://github.com/michivonah/nextjs.git
synced 2025-12-22 22:16:28 +01:00
implement error handling
This commit is contained in:
parent
39005d46a5
commit
7d2dea886c
5 changed files with 144 additions and 8 deletions
|
|
@ -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');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue