Skip to content

feat: implement response envelope with success and error handling#357

Merged
josephchimebuka merged 2 commits into
TevaLabs:mainfrom
somotochukwu-dev:standardize-hackathon-api-322
Jun 30, 2026
Merged

feat: implement response envelope with success and error handling#357
josephchimebuka merged 2 commits into
TevaLabs:mainfrom
somotochukwu-dev:standardize-hackathon-api-322

Conversation

@somotochukwu-dev

Copy link
Copy Markdown
Contributor

Summary

Closes #322

Standardize hackathon API responses to a consistent { success, data, meta? } envelope across all hackathon endpoints, replacing mixed raw arrays/objects.

Changes

New utility

  • src/utils/response.tssendSuccess(res, data, meta?, statusCode) and sendError(res, error, statusCode) helpers that produce the standard envelope. Success responses always return { success: true, data } with an optional meta key; errors return { success: false, error }.

Route migrations

Route Before After
GET /api (health) { status, timestamp, uptime, durationMs, services } { success: true, data: { status, timestamp, uptime, durationMs, services } }
GET /api/stats { success: true, data: {...} } (already wrapped) Uses helper, no shape change
GET /api/rounds res.json(rounds) / { source, rounds } { success: true, data: {...} }
GET /api/leaderboard Raw res.json(result) with pagination at top level { success: true, data: { leaderboard, totalUsers, ... }, meta: { pagination } }
GET /api/prices Raw res.json(prices) { success: true, data: { BTC, ETH, XLM, ... } }
POST /:id/bet, /hackathon/*/bet { success: true, message } { success: true, data: { message } }

Tests

  • src/tests/hackathon-rounds.spec.ts — Updated assertions to expect res.body.data.* envelope
  • src/tests/prices.routes.spec.ts — Updated assertions to expect res.body.data.* envelope
  • src/tests/response-envelope.spec.ts (new) — Validates all 5 hackathon endpoints return the standard envelope

Breaking changes

Frontend consumers must update response parsers:

  • Health (GET /api): response.statusresponse.data.status
  • Rounds (GET /api/rounds): response.sourceresponse.data.source, response.roundsresponse.data.rounds
  • Leaderboard (GET /api/leaderboard): response.leaderboardresponse.data.leaderboard, response.paginationresponse.meta.pagination
  • Prices (GET /api/prices): response.BTCresponse.data.BTC, response.ETHresponse.data.ETH, etc.
  • Bets (POST /:id/bet): response.messageresponse.data.message

Migration pattern for frontend:

// Before: ad-hoc per endpoint
const data = response.source ?? response.leaderboard ?? response;

// After: one parser for all
const { success, data, meta } = response;

@josephchimebuka josephchimebuka merged commit a6374f8 into TevaLabs:main Jun 30, 2026
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize hackathon API response envelope across endpoints

3 participants