feat(project): init

This commit is contained in:
zhangheng
2026-04-25 11:26:33 +08:00
commit 9bf212f67c
63 changed files with 11141 additions and 0 deletions

29
lib/http.ts Normal file
View File

@@ -0,0 +1,29 @@
import { NextResponse } from "next/server";
import type { HttpError } from "@/lib/types";
export function jsonError(
message: string,
statusCode = 500,
extra: Record<string, unknown> = {},
) {
return NextResponse.json(
{
ok: false,
error: message,
...extra,
},
{
status: statusCode,
},
);
}
export function normalizeError(error: unknown, fallbackMessage: string) {
const normalizedError = error as HttpError | null;
return {
statusCode: normalizedError?.statusCode ?? 500,
message: normalizedError?.message ?? fallbackMessage,
detail: normalizedError?.detail ?? null,
};
}