TrainsAndRoads/app/src/exceptions.ts

33 lines
857 B
TypeScript

import { WsException } from '@nestjs/websockets';
import { ErrorCode } from 'interface';
export abstract class WebSocketException extends WsException {
public readonly errorCode: ErrorCode;
constructor(message: string, errorCode: ErrorCode) {
super(message);
this.errorCode = errorCode;
}
}
export class MissingPlayerNameException extends WebSocketException {
constructor() {
super('Missing player name', ErrorCode.MISSING_USER_NAME);
}
}
export class PlayerNotFoundException extends WebSocketException {
constructor(playerId: string) {
super(
'Unable to find player from ID: ' + playerId,
ErrorCode.PLAYER_NOT_FOUND,
);
}
}
export class GameNotFoundException extends WebSocketException {
constructor(gameId: string) {
super('Unable to find game from ID: ' + gameId, ErrorCode.GAME_NOT_FOUND);
}
}