Files
TallyNote/server/errors.ts
T
Qiufeng 9719429f4a
TallyNote release / linux-x64 (push) Failing after 2m41s
feat: add TallyNote local reimbursement ledger
2026-08-29 01:02:29 +08:00

28 lines
660 B
TypeScript

import type { FastifyRequest } from "fastify";
export class AppError extends Error {
constructor(
public readonly statusCode: number,
public readonly code: string,
message: string,
public readonly details?: unknown,
) {
super(message);
}
}
export function errorPayload(request: FastifyRequest, error: AppError) {
return {
error: {
code: error.code,
message: error.message,
requestId: request.id,
...(error.details === undefined ? {} : { details: error.details }),
},
};
}
export function notFound(message = "没有找到对应内容"): never {
throw new AppError(404, "NOT_FOUND", message);
}