30 lines
765 B
TypeScript
30 lines
765 B
TypeScript
import { HttpException, HttpStatus } from '@nestjs/common';
|
|
|
|
export type RewardErrorCode = 'COMBAT_NOT_WON' | 'REWARD_STATE_INVALID';
|
|
|
|
export class RewardDomainError extends HttpException {
|
|
constructor(
|
|
public readonly code: RewardErrorCode,
|
|
status: HttpStatus,
|
|
message: string,
|
|
) {
|
|
super({ statusCode: status, code, message }, status);
|
|
}
|
|
}
|
|
|
|
export function combatNotWon(): RewardDomainError {
|
|
return new RewardDomainError(
|
|
'COMBAT_NOT_WON',
|
|
HttpStatus.CONFLICT,
|
|
'Only a won combat can grant victory rewards.',
|
|
);
|
|
}
|
|
|
|
export function rewardStateInvalid(): RewardDomainError {
|
|
return new RewardDomainError(
|
|
'REWARD_STATE_INVALID',
|
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
'The reward references unavailable data.',
|
|
);
|
|
}
|