wip
This commit is contained in:
56
packages/racing/application/errors/RacingApplicationError.ts
Normal file
56
packages/racing/application/errors/RacingApplicationError.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user