feat: standardize error envelope across all routes
BREAKING CHANGE: All API responses now use standardized envelope structure
Standardize response envelopes across all API routes for consistency and better developer experience.
- Updated
src/utils/response.tswith restructured error envelope - Modified
src/middleware/errorHandler.tsto use standardized helpers - Wrapped all route responses in success/error envelopes (8 route files)
- Updated tests to expect new envelope structure (3 test files)
- Updated documentation:
API_BEHAVIOR.mdandopenapi.yaml
Success:
{
"success": true,
"data": { /* payload */ },
"meta": { "timestamp": "...", "requestId": "..." }
}Error:
{
"success": false,
"error": { "code": "...", "message": "...", "requestId": "..." }
}- Access data through
response.datainstead ofresponse - Access errors through
response.errorinstead ofresponse.error.{field} - Error codes changed from
snake_casetoUPPER_SNAKE_CASE
- ✅ Consistent API surface across all endpoints
- ✅ Better debugging with requestId in all responses
- ✅ Type-safe response handling
- ✅ Follows REST API best practices
- ✅ All tests updated and passing
- ✅ No TypeScript errors
- ✅ Decimal string serialization preserved
21 files: +2,188 lines, -197 lines
Ready for review