Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances, roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map, alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js. Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push, bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
71 lines
4.1 KiB
JavaScript
71 lines
4.1 KiB
JavaScript
'use strict';
|
|
/*
|
|
* Stable API error codes. Clients switch on `code`, never on `message`. Every code the API can return is listed
|
|
* here with its HTTP status; docs/API.md and openapi.json are generated from this table.
|
|
*/
|
|
const CODES = {
|
|
bad_request: [400, 'The request could not be parsed.'],
|
|
validation_failed: [422, 'A field is missing or has the wrong shape.'],
|
|
unauthorized: [401, 'Missing, invalid or revoked token.'],
|
|
invalid_credentials: [401, 'Wrong username or password.'],
|
|
forbidden: [403, 'You may not do that.'],
|
|
not_found: [404, 'No such thing.'],
|
|
method_not_allowed: [405, 'Wrong HTTP method for this path.'],
|
|
conflict: [409, 'The request conflicts with the current state.'],
|
|
request_in_progress: [409, 'A request with this Idempotency-Key is still running.'],
|
|
idempotency_key_reuse: [422, 'This Idempotency-Key was used for a different request.'],
|
|
payload_too_large: [413, 'Request body too large.'],
|
|
rate_limited: [429, 'Too many requests, slow down.'],
|
|
internal_error: [500, 'Something broke on our side.'],
|
|
signup_closed: [403, 'Signup needs a valid invite code.'],
|
|
username_taken: [409, 'That username is taken.'],
|
|
world_full: [409, 'There is no room left on the map.'],
|
|
// game rules
|
|
unknown_building: [404, 'No such building or slot.'],
|
|
not_buildable: [409, 'That building cannot be built here.'],
|
|
max_level: [409, 'Already at the maximum level.'],
|
|
requirements_not_met: [409, 'A required building level is missing.'],
|
|
already_queued: [409, 'That building is already being built.'],
|
|
queue_full: [409, 'All build slots are busy.'],
|
|
not_enough_resources: [409, 'Not enough resources.'],
|
|
// social: alliances, diplomacy, messages
|
|
peering_office_required: [409, 'A Peering office (level 1 or higher) is needed to found or join an alliance.'],
|
|
already_in_alliance: [409, 'That operator is already in an alliance.'],
|
|
not_in_alliance: [409, 'You are not in that alliance.'],
|
|
alliance_name_taken: [409, 'That alliance name is taken.'],
|
|
alliance_tag_taken: [409, 'That alliance tag is taken.'],
|
|
alliance_full: [409, 'The alliance has no room for more members.'],
|
|
invite_expired: [409, 'The invite has expired.'],
|
|
leader_must_transfer: [409, 'The leader must hand over leadership before leaving.'],
|
|
notes_full: [409, 'The alliance has reached its pinned-note limit.'],
|
|
diplomacy_invalid: [409, 'That diplomatic move is not allowed from the current state.'],
|
|
diplomacy_pending: [409, 'A diplomatic change between these alliances is already scheduled.'],
|
|
proposal_exists: [409, 'The other alliance already proposed this; accept their proposal instead.'],
|
|
proposal_expired: [409, 'The proposal has expired.'],
|
|
// military and expansion
|
|
unknown_unit: [404, 'No such unit type.'],
|
|
not_researchable: [409, 'That unit stat cannot be researched.'],
|
|
not_enough_units: [409, 'Not enough units at home.'],
|
|
units_offline: [409, 'Those units are offline (the battery is empty).'],
|
|
invalid_target: [409, 'That target is not valid for this kind of movement.'],
|
|
target_protected: [409, 'The target is under beginner protection.'],
|
|
protection_active: [409, 'Attacking ends your beginner protection; confirm to go ahead.'],
|
|
out_of_range: [409, 'The target is too far from your POPs.'],
|
|
footprint_too_low: [409, 'Your footprint is too low for another POP.'],
|
|
cannot_takeover: [409, 'That POP cannot be taken over.'],
|
|
recall_expired: [409, 'The recall window (first 90 seconds) has passed.'],
|
|
capacity_exceeded: [409, 'More than one transport link can carry.'],
|
|
no_transport_link: [409, 'All transport links are busy (or there is no Internet exchange).'],
|
|
};
|
|
|
|
class GameError extends Error {
|
|
constructor(code, details, message) {
|
|
const def = CODES[code];
|
|
super(message || (def ? def[1] : code));
|
|
this.code = code;
|
|
this.status = def ? def[0] : 400;
|
|
this.details = details || {};
|
|
}
|
|
}
|
|
|
|
module.exports = { CODES, GameError };
|