feat(api): add equipment domain errors
This commit is contained in:
71
apps/api/src/equipment/equipment.errors.ts
Normal file
71
apps/api/src/equipment/equipment.errors.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
|
|
||||||
|
export type EquipmentErrorCode =
|
||||||
|
| 'CHARACTER_ITEM_NOT_FOUND'
|
||||||
|
| 'ITEM_NOT_OWNED'
|
||||||
|
| 'ITEM_NOT_EQUIPPABLE'
|
||||||
|
| 'ITEM_LEVEL_REQUIREMENT_NOT_MET'
|
||||||
|
| 'INVALID_EQUIPMENT_SLOT'
|
||||||
|
| 'CHARACTER_IN_COMBAT';
|
||||||
|
|
||||||
|
export class EquipmentDomainError extends HttpException {
|
||||||
|
constructor(
|
||||||
|
public readonly code: EquipmentErrorCode,
|
||||||
|
status: HttpStatus,
|
||||||
|
message: string,
|
||||||
|
) {
|
||||||
|
super({ statusCode: status, code, message }, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function characterItemNotFound(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'CHARACTER_ITEM_NOT_FOUND',
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
'This item could not be found.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itemNotOwned(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'ITEM_NOT_OWNED',
|
||||||
|
HttpStatus.FORBIDDEN,
|
||||||
|
'This item does not belong to the character.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itemNotEquippable(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'ITEM_NOT_EQUIPPABLE',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
'This item cannot be equipped.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itemLevelRequirementNotMet(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'ITEM_LEVEL_REQUIREMENT_NOT_MET',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"The character does not meet this item's level requirement.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defensive: slot is always derived from the item definition server-side, so
|
||||||
|
// this is unreachable in practice (spec §27 still names it explicitly).
|
||||||
|
export function invalidEquipmentSlot(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'INVALID_EQUIPMENT_SLOT',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
'This item does not target a valid equipment slot.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function characterInCombat(): EquipmentDomainError {
|
||||||
|
return new EquipmentDomainError(
|
||||||
|
'CHARACTER_IN_COMBAT',
|
||||||
|
HttpStatus.CONFLICT,
|
||||||
|
'Equipment cannot be changed during an active combat.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { characterNotFound } from '../travel/travel.errors';
|
||||||
Reference in New Issue
Block a user