Files
monorepo/baseball/src/app/api/_utils.ts
T
2026-05-06 15:08:32 +00:00

15 lines
470 B
TypeScript

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 });
}