wip
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
export abstract class RacingApplicationError extends Error {
|
||||
import type { IApplicationError, CommonApplicationErrorKind } from '@gridpilot/shared/errors';
|
||||
|
||||
export abstract class RacingApplicationError
|
||||
extends Error
|
||||
implements IApplicationError<CommonApplicationErrorKind | string, unknown>
|
||||
{
|
||||
readonly type = 'application' as const;
|
||||
readonly context = 'racing-application';
|
||||
abstract readonly kind: CommonApplicationErrorKind | string;
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
@@ -22,11 +29,16 @@ export interface EntityNotFoundDetails {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class EntityNotFoundError extends RacingApplicationError {
|
||||
export class EntityNotFoundError
|
||||
extends RacingApplicationError
|
||||
implements IApplicationError<'not_found', EntityNotFoundDetails>
|
||||
{
|
||||
readonly kind = 'not_found' as const;
|
||||
readonly details: EntityNotFoundDetails;
|
||||
|
||||
constructor(public readonly details: EntityNotFoundDetails) {
|
||||
constructor(details: EntityNotFoundDetails) {
|
||||
super(`${details.entity} not found for id: ${details.id}`);
|
||||
this.details = details;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,15 +51,25 @@ export type PermissionDeniedReason =
|
||||
| 'TEAM_OWNER_CANNOT_LEAVE'
|
||||
| 'UNAUTHORIZED';
|
||||
|
||||
export class PermissionDeniedError extends RacingApplicationError {
|
||||
export class PermissionDeniedError
|
||||
extends RacingApplicationError
|
||||
implements IApplicationError<'forbidden', PermissionDeniedReason>
|
||||
{
|
||||
readonly kind = 'forbidden' as const;
|
||||
|
||||
constructor(public readonly reason: PermissionDeniedReason, message?: string) {
|
||||
super(message ?? `Permission denied: ${reason}`);
|
||||
}
|
||||
|
||||
get details(): PermissionDeniedReason {
|
||||
return this.reason;
|
||||
}
|
||||
}
|
||||
|
||||
export class BusinessRuleViolationError extends RacingApplicationError {
|
||||
export class BusinessRuleViolationError
|
||||
extends RacingApplicationError
|
||||
implements IApplicationError<'conflict', undefined>
|
||||
{
|
||||
readonly kind = 'conflict' as const;
|
||||
|
||||
constructor(message: string) {
|
||||
|
||||
Reference in New Issue
Block a user