workign on api errors

This commit is contained in:
2024-09-09 19:52:47 -06:00
parent e1f1401592
commit 945253c208
12 changed files with 217 additions and 230 deletions

View File

@@ -0,0 +1,13 @@
import { NextResponse } from "next/server";
export async function withErrorHandling(handler: () => Promise<Response | NextResponse>) {
try {
return await handler();
} catch (error) {
console.error("Error caught in centralized handler:", error);
return NextResponse.json(
{ error: (error as Error).message || "Internal Server Error" },
{ status: 500 }
);
}
}