Background
The server currently sends error frames in the format { type: "error", payload: { message: "..." } } but with no machine-readable error code. Clients cannot programmatically distinguish between a validation error, rate limit, authentication failure, or room full condition — they can only parse free-text strings.
Category: Enhancement
Difficulty: Easy
Priority: Medium
Labels: enhancement, backend
Problem Statement
Without error codes, clients must string-match error messages to take action. This is brittle and breaks on any message wording change. A structured code field allows clients to handle errors programmatically.
Requirements
- Add a
code field to every error frame sent by the server.
- Define the following error codes as constants in a new
src/errors.js module:
INVALID_JSON
VALIDATION_ERROR
RATE_LIMITED
ROOM_FULL
AUTH_FAILED
- Update all
safeSend / error send call-sites in server.js to include the appropriate code.
- Document the error codes in
README.md under the Server-to-Client Messages table.
Acceptance Criteria
Files Likely to Change
src/errors.js (new)
src/server.js
README.md
tests/server.test.js
Definition of Done
Every error frame carries a code field. Clients can switch on code without parsing message strings.
Estimated Complexity
Easy — additive change; no logic modifications required.
Background
The server currently sends error frames in the format
{ type: "error", payload: { message: "..." } }but with no machine-readable error code. Clients cannot programmatically distinguish between a validation error, rate limit, authentication failure, or room full condition — they can only parse free-text strings.Category: Enhancement
Difficulty: Easy
Priority: Medium
Labels: enhancement, backend
Problem Statement
Without error codes, clients must string-match error messages to take action. This is brittle and breaks on any message wording change. A structured
codefield allows clients to handle errors programmatically.Requirements
codefield to every error frame sent by the server.src/errors.jsmodule:INVALID_JSONVALIDATION_ERRORRATE_LIMITEDROOM_FULLAUTH_FAILEDsafeSend/ error send call-sites inserver.jsto include the appropriate code.README.mdunder the Server-to-Client Messages table.Acceptance Criteria
{ type: "error", payload: { message: "...", code: "..." } }.src/errors.jsexports named constants for all codes.README.mddocuments each error code.codefield presence.npm run lintexits with code 0.Files Likely to Change
src/errors.js(new)src/server.jsREADME.mdtests/server.test.jsDefinition of Done
Every error frame carries a
codefield. Clients can switch oncodewithout parsing message strings.Estimated Complexity
Easy — additive change; no logic modifications required.