/** * Error Handling Utilities * * Standardized error handling for RevealUI framework. */ /** * Application Error * Use for business logic failures, validation failures, expected errors */ export declare class ApplicationError extends Error { code: string; statusCode: number; context?: Record | undefined; constructor(message: string, code: string, statusCode?: number, context?: Record | undefined); } /** * Validation Error * Use for input validation failures, schema validation failures */ export declare class ValidationError extends Error { field: string; value: unknown; context?: Record | undefined; constructor(message: string, field: string, value: unknown, context?: Record | undefined); } /** * Database Error * Use for database operation failures with Postgres error code parsing */ export declare class DatabaseError extends Error { code: string; statusCode: number; pgCode?: string | undefined; constraint?: string | undefined; table?: string | undefined; column?: string | undefined; context?: Record | undefined; constructor(message: string, code: string, statusCode?: number, pgCode?: string | undefined, constraint?: string | undefined, table?: string | undefined, column?: string | undefined, context?: Record | undefined); } /** * Authentication Error * Use for failed login, expired sessions, invalid tokens */ export declare class AuthenticationError extends ApplicationError { constructor(message?: string, context?: Record); } /** * Authorization Error * Use for insufficient permissions, forbidden access */ export declare class AuthorizationError extends ApplicationError { constructor(message?: string, context?: Record); } /** * Not Found Error * Use for missing resources (users, posts, pages, etc.) */ export declare class NotFoundError extends ApplicationError { constructor(resource: string, identifier?: string, context?: Record); } /** * Conflict Error * Use for duplicate resources, concurrent modification conflicts */ export declare class ConflictError extends ApplicationError { constructor(message?: string, context?: Record); } /** * Rate Limit Error * Use for too many requests, throttling */ export declare class RateLimitError extends ApplicationError { retryAfterMs?: number | undefined; constructor(message?: string, retryAfterMs?: number | undefined, context?: Record); } /** * Postgres Error Codes * Reference: https://www.postgresql.org/docs/current/errcodes-appendix.html */ export declare const PostgresErrorCode: { readonly UNIQUE_VIOLATION: "23505"; readonly FOREIGN_KEY_VIOLATION: "23503"; readonly NOT_NULL_VIOLATION: "23502"; readonly CHECK_VIOLATION: "23514"; readonly UNDEFINED_TABLE: "42P01"; readonly UNDEFINED_COLUMN: "42703"; readonly DUPLICATE_TABLE: "42P07"; readonly DUPLICATE_COLUMN: "42701"; readonly DEADLOCK_DETECTED: "40P01"; readonly SERIALIZATION_FAILURE: "40001"; readonly QUERY_CANCELED: "57014"; readonly ADMIN_SHUTDOWN: "57P01"; readonly DISK_FULL: "53100"; readonly OUT_OF_MEMORY: "53200"; readonly TOO_MANY_CONNECTIONS: "53300"; readonly CONNECTION_EXCEPTION: "08000"; readonly CONNECTION_FAILURE: "08006"; readonly CONNECTION_DOES_NOT_EXIST: "08003"; readonly INVALID_TRANSACTION_STATE: "25000"; readonly ACTIVE_SQL_TRANSACTION: "25001"; }; /** * Handle and log error in API routes * * @param error - The error to handle * @param context - Additional context to log * @returns User-friendly error message */ export declare function handleApiError(error: unknown, context?: Record): { message: string; statusCode: number; code?: string; retryable?: boolean; }; /** * Handle database errors with Postgres error code parsing * * @param error - Database error * @param operation - Operation being performed (e.g., 'insert user', 'update order') * @param context - Additional context (e.g., { userId: '123', table: 'users' }) * @returns Never - always throws a DatabaseError * * @example * ```typescript * try { * await db.insert(users).values({ email: 'existing@example.com' }) * } catch (error) { * handleDatabaseError(error, 'insert user', { email: 'existing@example.com' }) * } * ``` */ export declare function handleDatabaseError(error: unknown, operation: string, context?: Record): never; //# sourceMappingURL=errors.d.ts.map