Implement Centralized API Error Handling
Priority
P0 — Critical
Labels
backend architecture security priority: p0
Description
Mind Block requires a consistent error-handling strategy across all backend modules. Currently, different services may return errors in different formats, making it difficult for the frontend to reliably display meaningful feedback.
A centralized exception-handling system should provide predictable API error responses while preventing sensitive internal information from being exposed to users.
Objective
Implement a global NestJS exception filter and standardized API error response format.
Standard Error Response
All API errors should follow a consistent structure:
{
"success": false,
"statusCode": 400,
"error": "Bad Request",
"message": "A human-readable error message",
"code": "VALIDATION_ERROR",
"timestamp": "2026-08-20T12:00:00.000Z",
"path": "/api/game-sessions"
}
Error Categories
Support standardized error codes for:
VALIDATION_ERROR
UNAUTHORIZED
FORBIDDEN
NOT_FOUND
CONFLICT
RATE_LIMITED
SESSION_EXPIRED
SESSION_INVALID
CHALLENGE_UNAVAILABLE
INVALID_ANSWER
DUPLICATE_SUBMISSION
REWARD_NOT_ELIGIBLE
BLOCKCHAIN_ERROR
INTERNAL_SERVER_ERROR
Requirements
- Create a global exception filter.
- Standardize error response structures.
- Map NestJS exceptions to application error codes.
- Handle validation errors.
- Handle database errors safely.
- Handle authentication errors.
- Handle authorization errors.
- Handle unexpected server errors.
- Prevent stack traces from being exposed in production.
- Log unexpected server errors.
- Include a unique request ID where applicable.
Acceptance Criteria
Dependencies
None.
Implement Centralized API Error Handling
Priority
P0 — Critical
Labels
backendarchitecturesecuritypriority: p0Description
Mind Block requires a consistent error-handling strategy across all backend modules. Currently, different services may return errors in different formats, making it difficult for the frontend to reliably display meaningful feedback.
A centralized exception-handling system should provide predictable API error responses while preventing sensitive internal information from being exposed to users.
Objective
Implement a global NestJS exception filter and standardized API error response format.
Standard Error Response
All API errors should follow a consistent structure:
{ "success": false, "statusCode": 400, "error": "Bad Request", "message": "A human-readable error message", "code": "VALIDATION_ERROR", "timestamp": "2026-08-20T12:00:00.000Z", "path": "/api/game-sessions" }Error Categories
Support standardized error codes for:
Requirements
Acceptance Criteria
Dependencies
None.