mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
workign on api errors
This commit is contained in:
13
nextjs/src/services/withErrorHandling.ts
Normal file
13
nextjs/src/services/withErrorHandling.ts
Normal 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user