UNPKG

@spfn/core

Version:

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

172 lines (169 loc) 5.34 kB
// src/errors/database-errors.ts var DatabaseError = class extends Error { statusCode; details; timestamp; constructor(message, statusCode = 500, details) { super(message); this.name = "DatabaseError"; this.statusCode = statusCode; this.details = details; this.timestamp = /* @__PURE__ */ new Date(); Error.captureStackTrace(this, this.constructor); } /** * Serialize error for API response */ toJSON() { return { name: this.name, message: this.message, statusCode: this.statusCode, details: this.details, timestamp: this.timestamp.toISOString() }; } }; var ConnectionError = class extends DatabaseError { constructor(message, details) { super(message, 503, details); this.name = "ConnectionError"; } }; var QueryError = class extends DatabaseError { constructor(message, statusCode = 500, details) { super(message, statusCode, details); this.name = "QueryError"; } }; var EntityNotFoundError = class extends QueryError { constructor(resource, id) { super(`${resource} with id ${id} not found`, 404, { resource, id }); this.name = "EntityNotFoundError"; } }; var ConstraintViolationError = class extends QueryError { constructor(message, details) { super(message, 400, details); this.name = "ConstraintViolationError"; } }; var TransactionError = class extends DatabaseError { constructor(message, statusCode = 500, details) { super(message, statusCode, details); this.name = "TransactionError"; } }; var DeadlockError = class extends TransactionError { constructor(message, details) { super(message, 409, details); this.name = "DeadlockError"; } }; var DuplicateEntryError = class extends QueryError { constructor(field, value) { super(`${field} '${value}' already exists`, 409, { field, value }); this.name = "DuplicateEntryError"; } }; // src/errors/http-errors.ts var HttpError = class extends Error { statusCode; details; timestamp; constructor(message, statusCode, details) { super(message); this.name = "HttpError"; this.statusCode = statusCode; this.details = details; this.timestamp = /* @__PURE__ */ new Date(); Error.captureStackTrace(this, this.constructor); } /** * Serialize error for API response */ toJSON() { return { name: this.name, message: this.message, statusCode: this.statusCode, details: this.details, timestamp: this.timestamp.toISOString() }; } }; var BadRequestError = class extends HttpError { constructor(message = "Bad request", details) { super(message, 400, details); this.name = "BadRequestError"; } }; var ValidationError = class extends HttpError { constructor(message, details) { super(message, 400, details); this.name = "ValidationError"; } }; var UnauthorizedError = class extends HttpError { constructor(message = "Authentication required", details) { super(message, 401, details); this.name = "UnauthorizedError"; } }; var ForbiddenError = class extends HttpError { constructor(message = "Access forbidden", details) { super(message, 403, details); this.name = "ForbiddenError"; } }; var NotFoundError = class extends HttpError { constructor(message = "Resource not found", details) { super(message, 404, details); this.name = "NotFoundError"; } }; var ConflictError = class extends HttpError { constructor(message = "Resource conflict", details) { super(message, 409, details); this.name = "ConflictError"; } }; var TooManyRequestsError = class extends HttpError { constructor(message = "Too many requests", retryAfter, details) { const fullDetails = retryAfter ? { ...details, retryAfter } : details; super(message, 429, fullDetails); this.name = "TooManyRequestsError"; } }; var InternalServerError = class extends HttpError { constructor(message = "Internal server error", details) { super(message, 500, details); this.name = "InternalServerError"; } }; var UnprocessableEntityError = class extends HttpError { constructor(message = "Unprocessable entity", details) { super(message, 422, details); this.name = "UnprocessableEntityError"; } }; var ServiceUnavailableError = class extends HttpError { constructor(message = "Service unavailable", retryAfter, details) { const fullDetails = retryAfter ? { ...details, retryAfter } : details; super(message, 503, fullDetails); this.name = "ServiceUnavailableError"; } }; // src/errors/error-utils.ts function isDatabaseError(error) { return error instanceof DatabaseError; } function isHttpError(error) { return error instanceof HttpError; } function hasStatusCode(error) { return typeof error === "object" && error !== null && "statusCode" in error && typeof error.statusCode === "number"; } export { BadRequestError, ConflictError, ConnectionError, ConstraintViolationError, DatabaseError, DeadlockError, DuplicateEntryError, EntityNotFoundError, ForbiddenError, HttpError, InternalServerError, NotFoundError, QueryError, ServiceUnavailableError, TooManyRequestsError, TransactionError, UnauthorizedError, UnprocessableEntityError, ValidationError, hasStatusCode, isDatabaseError, isHttpError }; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map