Skip to content

Add structured error codes to all server-to-client error frames #179

Description

@levibliz

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

  • All error frames include { type: "error", payload: { message: "...", code: "..." } }.
  • src/errors.js exports named constants for all codes.
  • README.md documents each error code.
  • Existing error-related tests updated to assert code field presence.
  • npm run lint exits with code 0.

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.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions