Updating
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { ZodError } from "zod";
|
||||
|
||||
export function handleApiError(error: unknown) {
|
||||
if (error instanceof ZodError) {
|
||||
return NextResponse.json({ error: error.issues[0]?.message ?? "Validation failed." }, { status: 400 });
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "Unexpected server error." }, { status: 500 });
|
||||
}
|
||||
Reference in New Issue
Block a user