/
foult080
/
terminal-db
Обзор
Документация
Войти
/
foult080
/
terminal-db
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/core/errors/AppError.ts
40 строк
1 KB
foult080
refactor(): fix some voulnerabilities
13 июл 2026, 14:18
13 июл 2026, 14:18
c520ea5
Код
Авторство
О чём код?
export class AppError extends Error { constructor( message: string, public code: string, public statusCode = 500, public details?: Record<string, unknown>, ) { super(message) this.name = "AppError" } static notFound(entity: string, id: string): AppError { return new AppError(`${entity} with id "${id}" not found`, "NOT_FOUND", 404) } static validation(message: string, details?: Record<string, unknown>): AppError { return new AppError(message, "VALIDATION_ERROR", 400, details) } static connection(message: string, details?: Record<string, unknown>): AppError { return new AppError(message, "CONNECTION_ERROR", 502, details) } static internal(message: string, cause?: Error): AppError { const error = new AppError(message, "INTERNAL_ERROR", 500) error.cause = cause return error } toJSON(): Record<string, unknown> { return { name: this.name, message: this.message, code: this.code, statusCode: this.statusCode, details: this.details, ...(this.cause ? { cause: (this.cause as Error).message } : {}), } } }