import { BadRequestException, ConflictException, NotFoundException, } from '@nestjs/common'; import type { HiveState } from './hive-types'; /** 409: an operation failed against the current state (spec 6.2). */ export class HiveConflictException extends ConflictException { constructor( opIndex: number, reason: string, current: { version: number; state: HiveState }, ) { super({ statusCode: 409, code: 'HIVE_CONFLICT', message: 'Die Änderung passt nicht mehr zum aktuellen Aufbau.', opIndex, reason, current, }); } } export function hiveNotFound(): NotFoundException { return new NotFoundException({ statusCode: 404, code: 'HIVE_NOT_FOUND', message: 'Für dieses Volk gibt es noch keinen Aufbau.', }); } export function hiveExists(): ConflictException { return new ConflictException({ statusCode: 409, code: 'HIVE_EXISTS', message: 'Für dieses Volk gibt es schon einen Aufbau.', }); } export function invalidDay(field: string): BadRequestException { return new BadRequestException(`${field} must be a valid YYYY-MM-DD day`); }