export class AppError extends Error { constructor( readonly code: string, message: string, readonly status = 400, readonly details?: unknown, ) { super(message); } toJSON() { return { error: { code: this.code, message: this.message, details: this.details ?? undefined } }; } } export const notFound = (what: string) => new AppError("not_found", `${what} not found`, 404); export const forbidden = (msg = "forbidden") => new AppError("forbidden", msg, 403); export const unauthorized = (msg = "authentication required") => new AppError("unauthorized", msg, 401); export const conflict = (msg: string, details?: unknown) => new AppError("conflict", msg, 409, details); export const invalid = (msg: string, details?: unknown) => new AppError("invalid", msg, 400, details);