Skip to content

B5: Return stable API error codes - #2

Merged
Filionus merged 2 commits into
mainfrom
fix/b5-api-errors
Nov 26, 2026
Merged

Filionus merged 2 commits into
mainfrom
fix/b5-api-errors

Conversation

@ChargingCrystal

Copy link
Copy Markdown
Owner

B5

  • Add stable data.code values to errors from all 14 API handlers. Map invite and date failures by operation and keep upstream diagnostics on the server.
  • Validate date UUIDs before contacting Supabase and return no_space for unpaired date and location writes.
  • Publish the route contract in the README and export shared Zod schemas and TypeScript types.

Frontend impact

Map the JSON response's data.code to an i18n key using ApiErrorCode from shared/api-errors.ts. Keep the sign-in handling for HTTP 401 and use a generic translated fallback for responses without an API error envelope. Successful responses retain their existing shapes.

A bearer-authenticated PATCH /api/dates/not-a-uuid with {"title":"Cinema"} returns HTTP 400 with contract fields {"statusCode":400,"data":{"code":"validation_failed"}}. Unpaired date and location writes return 403 no_space. Photo validation retains 413 and 415.

Tests

  • Red commit 4675d39 captured 17 failures before the implementation.
  • Added HTTP coverage for all seven error codes and shared success-schema coverage for all 14 routes, using actual handlers with simulated Supabase responses.
  • npm test passed all 42 tests. npm run build passed. The built Nitro server returned the expected health, unauthorized, and malformed-UUID responses.

@Filionus
Filionus merged commit 3e26cae into main Nov 26, 2026
1 check passed
@ChargingCrystal
ChargingCrystal deleted the fix/b5-api-errors branch November 26, 2026 09:58
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.

2 participants