UNPKG

adonis-odm

Version:

A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support

82 lines (81 loc) 2.67 kB
/** * Base exception for MongoDB ODM */ export class MongoOdmException extends Error { constructor(message) { super(message); this.name = this.constructor.name; } } /** * Exception thrown when a model is not found */ export class ModelNotFoundException extends MongoOdmException { constructor(model, identifier) { const message = identifier ? `${model} with identifier "${identifier}" not found` : `${model} not found`; super(message); } } /** * Exception thrown when connection fails */ export class ConnectionException extends MongoOdmException { constructor(connectionName, originalError) { const message = `Failed to connect to MongoDB connection "${connectionName}"`; super(originalError ? `${message}: ${originalError.message}` : message); } } /** * Exception thrown when database operations fail */ export class DatabaseOperationException extends MongoOdmException { constructor(operation, originalError) { const message = `Database operation "${operation}" failed`; super(originalError ? `${message}: ${originalError.message}` : message); } } /** * Exception thrown when validation fails */ export class ValidationException extends MongoOdmException { constructor(field, value, rule) { super(`Validation failed for field "${field}" with value "${value}": ${rule}`); } } /** * Exception thrown when transaction operations fail */ export class TransactionException extends MongoOdmException { constructor(operation, originalError) { const message = `Transaction operation "${operation}" failed`; super(originalError ? `${message}: ${originalError.message}` : message); } } /** * Exception thrown when hook execution fails */ export class HookExecutionException extends MongoOdmException { constructor(hookName, modelName, originalError) { const message = `Hook "${hookName}" failed for model "${modelName}"`; super(originalError ? `${message}: ${originalError.message}` : message); } } /** * Exception thrown when relationship loading fails */ export class RelationshipException extends MongoOdmException { constructor(relationshipName, modelName, originalError) { const message = `Failed to load relationship "${relationshipName}" for model "${modelName}"`; super(originalError ? `${message}: ${originalError.message}` : message); } } /** * Exception thrown when configuration is invalid */ export class ConfigurationException extends MongoOdmException { constructor(message) { super(`Configuration error: ${message}`); } }