feat: initialize CalBook project with comprehensive scheduling, admin, and deployment infrastructure
This commit is contained in:
21
lib/api.ts
Normal file
21
lib/api.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export function ok(data: unknown, status = 200) {
|
||||
return NextResponse.json(data, { status });
|
||||
}
|
||||
|
||||
export function fail(message: string, status = 400, details?: unknown) {
|
||||
return NextResponse.json({ message, details }, { status });
|
||||
}
|
||||
|
||||
export function handleAuthError(error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
if (error.message === "UNAUTHORIZED") {
|
||||
return fail("Nicht angemeldet", 401);
|
||||
}
|
||||
if (error.message === "FORBIDDEN") {
|
||||
return fail("Keine Berechtigung", 403);
|
||||
}
|
||||
}
|
||||
return fail("Interner Fehler", 500);
|
||||
}
|
||||
Reference in New Issue
Block a user