Error Response Format
All errors follow a consistent JSON structure:Error Classes
The API uses custom error classes that extend the baseAppError class. Each error class corresponds to a specific HTTP status code.
Base Error Class
HTTP Status Codes
400 - Bad Request
The request is malformed or contains invalid parameters. Error Class:BadRequestError
401 - Unauthorized
Authentication is required or the provided token is invalid. Error Class:UnauthorizedError
- No authentication token provided
- Token is expired or malformed
- Invalid credentials during login
403 - Forbidden
Authentication succeeded but the user lacks permission to access the resource. Error Class:ForbiddenError
- Customer trying to access admin-only endpoints
- User trying to modify another user’s resources
404 - Not Found
The requested resource does not exist. Error Class:NotFoundError
409 - Conflict
The request conflicts with the current state of the server. Error Class:ConflictError
- Email already registered during signup
- Duplicate resource creation
422 - Unprocessable Entity
The request is well-formed but contains semantic errors (validation failures). Error Class:ValidationError
- Missing required fields
- Invalid email format
- Password too short
- Invalid enum values
429 - Too Many Requests
Rate limit exceeded for the endpoint. Example Response:POST /auth/register- 10 requests per 15 minutesPOST /auth/login- 10 requests per 15 minutes
/workspace/source/backend/src/routes/auth.routes.ts:15-21
500 - Internal Server Error
An unexpected error occurred on the server. Error Class:InternalServerError
Error Middleware
The API uses centralized error handling middleware:Validation Errors
Validation is performed using class-validator. When validation fails, you receive detailed error messages. Example Validation Error: Request:| Field | Validation | Error Message |
|---|---|---|
| Valid email format | ”email must be a valid email” | |
| password | Minimum 6 characters | ”La contraseña debe tener al menos 6 caracteres” |
| role | Must be ‘customer’ or ‘admin‘ | “El rol debe ser ‘customer’ o ‘admin‘“ |
| name | Required string | ”name should not be empty” |
Error Handling Best Practices
Client-Side Error Handling
Always check the HTTP status code and handle errors appropriately:Retry Logic
For rate-limited requests (429), implement exponential backoff:Token Expiration
Handle token expiration gracefully:Status Code Summary
| Code | Class | Description |
|---|---|---|
| 200 | Success | Request succeeded |
| 201 | Success | Resource created successfully |
| 400 | BadRequestError | Malformed request |
| 401 | UnauthorizedError | Authentication required or failed |
| 403 | ForbiddenError | Insufficient permissions |
| 404 | NotFoundError | Resource not found |
| 409 | ConflictError | Resource conflict (e.g., duplicate) |
| 422 | ValidationError | Validation failed |
| 429 | Rate Limit | Too many requests |
| 500 | InternalServerError | Server error |
Debugging Tips
- Check the status code first - It tells you the category of error
- Read the error message - Provides specific details about what went wrong
- Verify authentication - Many errors stem from missing or invalid tokens
- Validate input data - Ensure your request body matches the expected schema
- Check rate limits - Wait and retry if you hit rate limits
- Review documentation - Ensure you’re using the correct endpoint and method