46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
|
|
/**
|
||
|
|
* Domain Errors
|
||
|
|
* Specific error types for domain invariants
|
||
|
|
*/
|
||
|
|
|
||
|
|
export abstract class DomainError extends Error {
|
||
|
|
abstract readonly code: string;
|
||
|
|
|
||
|
|
constructor(message: string) {
|
||
|
|
super(message);
|
||
|
|
this.name = this.constructor.name;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class InvariantViolationError extends DomainError {
|
||
|
|
readonly code = 'INVARIANT_VIOLATION';
|
||
|
|
|
||
|
|
constructor(message: string) {
|
||
|
|
super(message);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class InvalidStateTransitionError extends DomainError {
|
||
|
|
readonly code = 'INVALID_STATE_TRANSITION';
|
||
|
|
|
||
|
|
constructor(from: string, to: string) {
|
||
|
|
super(`Cannot transition from ${from} to ${to}`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class MissingRequiredFieldError extends DomainError {
|
||
|
|
readonly code = 'MISSING_REQUIRED_FIELD';
|
||
|
|
|
||
|
|
constructor(field: string) {
|
||
|
|
super(`Missing required field: ${field}`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class InvalidIdFormatError extends DomainError {
|
||
|
|
readonly code = 'INVALID_ID_FORMAT';
|
||
|
|
|
||
|
|
constructor(id: string, expectedFormat: string) {
|
||
|
|
super(`Invalid ID format: ${id}. Expected: ${expectedFormat}`);
|
||
|
|
}
|
||
|
|
}
|