mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 09:14:11 +05:30
26 lines
535 B
TypeScript
26 lines
535 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getErrorMessage } from "./errors";
|
|
|
|
export function jsonError(
|
|
error: unknown,
|
|
options?: {
|
|
status?: number;
|
|
fallback?: string;
|
|
headers?: HeadersInit;
|
|
},
|
|
) {
|
|
return NextResponse.json(
|
|
{
|
|
error: getErrorMessage(error, options?.fallback ?? "请求失败"),
|
|
},
|
|
{
|
|
status: options?.status ?? 500,
|
|
headers: options?.headers,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function jsonOk<T>(data: T, init?: ResponseInit) {
|
|
return NextResponse.json(data, init);
|
|
}
|