commit
75e03b42f7
99 files changed
+12285
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export function json<T>(data: T, init?: ResponseInit) {
|
||||
return NextResponse.json(data, init);
|
||||
}
|
||||
|
||||
export function err(message: string, status = 400) {
|
||||
return NextResponse.json({ error: message }, { status });
|
||||
}
|
||||
|
||||
export function asResponse(e: unknown): Response {
|
||||
if (e instanceof Response) return e;
|
||||
console.error(e);
|
||||
const msg = e instanceof Error ? e.message : "Internal error";
|
||||
return NextResponse.json({ error: msg }, { status: 500 });
|
||||
}
|
||||
Reference in new issue
Block a user