spb/autoscholar
Public
1export class AppError extends Error {2 constructor(3 readonly code: string,4 message: string,5 readonly status = 400,6 readonly details?: unknown,7 ) {8 super(message);9 }10 toJSON() {11 return { error: { code: this.code, message: this.message, details: this.details ?? undefined } };12 }13}14export const notFound = (what: string) => new AppError("not_found", `${what} not found`, 404);15export const forbidden = (msg = "forbidden") => new AppError("forbidden", msg, 403);16export const unauthorized = (msg = "authentication required") => new AppError("unauthorized", msg, 401);17export const conflict = (msg: string, details?: unknown) => new AppError("conflict", msg, 409, details);18export const invalid = (msg: string, details?: unknown) => new AppError("invalid", msg, 400, details);19