This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -0,0 +1,56 @@
export abstract class RacingApplicationError extends Error {
readonly context = 'racing-application';
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}
export type RacingEntityType =
| 'race'
| 'league'
| 'team'
| 'season'
| 'sponsorship'
| 'sponsorshipRequest'
| 'driver'
| 'membership';
export interface EntityNotFoundDetails {
entity: RacingEntityType;
id: string;
}
export class EntityNotFoundError extends RacingApplicationError {
readonly kind = 'not_found' as const;
constructor(public readonly details: EntityNotFoundDetails) {
super(`${details.entity} not found for id: ${details.id}`);
}
}
export type PermissionDeniedReason =
| 'NOT_LEAGUE_ADMIN'
| 'NOT_LEAGUE_OWNER'
| 'NOT_TEAM_OWNER'
| 'NOT_ACTIVE_MEMBER'
| 'NOT_MEMBER'
| 'TEAM_OWNER_CANNOT_LEAVE'
| 'UNAUTHORIZED';
export class PermissionDeniedError extends RacingApplicationError {
readonly kind = 'forbidden' as const;
constructor(public readonly reason: PermissionDeniedReason, message?: string) {
super(message ?? `Permission denied: ${reason}`);
}
}
export class BusinessRuleViolationError extends RacingApplicationError {
readonly kind = 'conflict' as const;
constructor(message: string) {
super(message);
}
}