feat(combat): add combat domain errors
This commit is contained in:
87
apps/api/src/combat/combat.errors.ts
Normal file
87
apps/api/src/combat/combat.errors.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||
|
||||
export type CombatErrorCode =
|
||||
| 'HUNT_ENCOUNTER_NOT_FOUND'
|
||||
| 'HUNT_ENCOUNTER_ALREADY_CONSUMED'
|
||||
| 'INVALID_HUNT_ENCOUNTER'
|
||||
| 'CHARACTER_TRAVELLING'
|
||||
| 'COMBAT_ALREADY_ACTIVE'
|
||||
| 'COMBAT_NOT_FOUND'
|
||||
| 'COMBAT_ALREADY_FINISHED'
|
||||
| 'COMBAT_STATE_INVALID';
|
||||
|
||||
export class CombatDomainError extends HttpException {
|
||||
constructor(
|
||||
public readonly code: CombatErrorCode,
|
||||
status: HttpStatus,
|
||||
message: string,
|
||||
) {
|
||||
super({ statusCode: status, code, message }, status);
|
||||
}
|
||||
}
|
||||
|
||||
export function huntEncounterNotFound(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'HUNT_ENCOUNTER_NOT_FOUND',
|
||||
HttpStatus.NOT_FOUND,
|
||||
'This encounter could not be found.',
|
||||
);
|
||||
}
|
||||
|
||||
export function huntEncounterAlreadyConsumed(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'HUNT_ENCOUNTER_ALREADY_CONSUMED',
|
||||
HttpStatus.CONFLICT,
|
||||
'This encounter has already been used to start a combat.',
|
||||
);
|
||||
}
|
||||
|
||||
export function invalidHuntEncounter(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'INVALID_HUNT_ENCOUNTER',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
'This encounter is not valid for the current character.',
|
||||
);
|
||||
}
|
||||
|
||||
export function characterTravelling(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'CHARACTER_TRAVELLING',
|
||||
HttpStatus.CONFLICT,
|
||||
'The character cannot fight while travelling.',
|
||||
);
|
||||
}
|
||||
|
||||
export function combatAlreadyActive(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'COMBAT_ALREADY_ACTIVE',
|
||||
HttpStatus.CONFLICT,
|
||||
'The character already has an active combat.',
|
||||
);
|
||||
}
|
||||
|
||||
export function combatNotFound(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'COMBAT_NOT_FOUND',
|
||||
HttpStatus.NOT_FOUND,
|
||||
'This combat could not be found.',
|
||||
);
|
||||
}
|
||||
|
||||
export function combatAlreadyFinished(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'COMBAT_ALREADY_FINISHED',
|
||||
HttpStatus.CONFLICT,
|
||||
'This combat has already finished.',
|
||||
);
|
||||
}
|
||||
|
||||
export function combatStateInvalid(): CombatDomainError {
|
||||
return new CombatDomainError(
|
||||
'COMBAT_STATE_INVALID',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
'The persisted combat references unavailable data.',
|
||||
);
|
||||
}
|
||||
|
||||
export { characterNotFound } from '../travel/travel.errors';
|
||||
Reference in New Issue
Block a user