mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 09:14:11 +05:30
Initial commit
This commit is contained in:
25
src/lib/api-response.ts
Normal file
25
src/lib/api-response.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user