Add /api/events error codes

400 for invalid event (schema violated)
500 for clickhouse error
This commit is contained in:
John Richmond 2025-05-14 17:30:18 -07:00
parent 3aff8994ae
commit 2f5212a2b1

View file

@ -21,16 +21,22 @@ export async function POST(request: NextRequest) {
const result = eventSchema.safeParse({ ...payload, id, userId, timestamp });
if (!result.success) {
return NextResponse.json({ success: false, error: result.error.message });
return NextResponse.json(
{ success: false, error: result.error.message },
{ status: 400 },
);
}
try {
await captureEvent(result.data);
} catch (error) {
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
});
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
},
{ status: 500 },
);
}
return NextResponse.json({ success: true, id });