deadhead-space-freight-tycoon/packages/engine/src/game/errors.ts

26 lines
701 B
TypeScript

import type { ErrorCode } from "@deadhead/schema";
/**
* A refused command (CR-014): the same codes and messages the server sent, so
* the client and the ported tests read them as before.
*/
export class CommandError extends Error {
constructor(
readonly code: ErrorCode,
message: string,
) {
super(message);
this.name = "CommandError";
}
}
export const fail = (code: ErrorCode, message: string) => new CommandError(code, message);
/** Codes the server answered with 404 rather than 409 (for HTTP-shaped tests and the client). */
export const NOT_FOUND_CODES: ReadonlySet<ErrorCode> = new Set([
"not-found",
"unknown-contract",
"unknown-skill",
"unknown-goal",
]);