UNPKG

@spfn/core

Version:

SPFN Framework Core - File-based routing, transactions, repository pattern

137 lines (132 loc) 4.1 kB
import { D as DatabaseError } from '../database-errors-BNNmLTJE.js'; export { C as ConnectionError, a as ConstraintViolationError, b as DeadlockError, c as DuplicateEntryError, E as EntityNotFoundError, Q as QueryError, T as TransactionError } from '../database-errors-BNNmLTJE.js'; /** * HTTP Error Classes * * Standard HTTP error classes for API responses * Covers common HTTP status codes beyond database errors */ /** * Base HTTP Error * * Base class for all HTTP-related errors */ declare class HttpError<TDetails extends Record<string, unknown> = Record<string, unknown>> extends Error { readonly statusCode: number; readonly details?: TDetails; readonly timestamp: Date; constructor(message: string, statusCode: number, details?: TDetails); /** * Serialize error for API response */ toJSON(): { name: string; message: string; statusCode: number; details: TDetails | undefined; timestamp: string; }; } /** * Bad Request Error (400) * * Generic bad request - malformed syntax, invalid parameters, etc. */ declare class BadRequestError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Validation Error (400) * * Input validation failure (request params, query, body) * Used by contract-based routing for automatic validation */ declare class ValidationError extends HttpError { constructor(message: string, details?: Record<string, any>); } /** * Unauthorized Error (401) * * Authentication required or authentication failed */ declare class UnauthorizedError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Forbidden Error (403) * * Authenticated but lacks permission to access resource */ declare class ForbiddenError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Not Found Error (404) * * Requested resource does not exist * Generic HTTP 404 error (for database-specific NotFoundError, see database-errors.ts) */ declare class NotFoundError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Conflict Error (409) * * Generic conflict - resource state conflict, concurrent modification, etc. * More general than DuplicateEntryError */ declare class ConflictError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Too Many Requests Error (429) * * Rate limit exceeded */ declare class TooManyRequestsError extends HttpError { constructor(message?: string, retryAfter?: number, details?: Record<string, any>); } /** * Internal Server Error (500) * * Generic server error when no specific error type applies */ declare class InternalServerError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Unprocessable Entity Error (422) * * Request is well-formed but contains semantic errors */ declare class UnprocessableEntityError extends HttpError { constructor(message?: string, details?: Record<string, any>); } /** * Service Unavailable Error (503) * * Service temporarily unavailable (maintenance, overload, etc.) */ declare class ServiceUnavailableError extends HttpError { constructor(message?: string, retryAfter?: number, details?: Record<string, any>); } /** * Error Utility Functions * * Generic error type checking utilities */ /** * Check if error is a DatabaseError */ declare function isDatabaseError(error: unknown): error is DatabaseError; /** * Check if error is an HttpError */ declare function isHttpError(error: unknown): error is HttpError; /** * Check if error has a statusCode property */ declare function hasStatusCode(error: unknown): error is { statusCode: number; }; export { BadRequestError, ConflictError, DatabaseError, ForbiddenError, HttpError, InternalServerError, NotFoundError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, ValidationError, hasStatusCode, isDatabaseError, isHttpError };