17 lines
498 B
TypeScript
17 lines
498 B
TypeScript
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 });
|
|
}
|