Error Handling
Console uses standard HTTP status codes and consistent error response formats.
HTTP Status Codes
| Code | Meaning |
|---|---|
200 | Success |
201 | Created |
400 | Bad request (business logic error) |
401 | Not authenticated (invalid/missing token) |
403 | Not authorized (insufficient permissions) |
404 | Resource not found |
422 | Validation error (invalid request format) |
429 | Rate limit exceeded |
Error Response Format
Business Logic Errors (400)
{
"error": "User with this email already exists",
"error_code": "USER_EMAIL_DUPLICATE"
}
Validation Errors (422)
{
"errors": [
{
"field": "email",
"message": "must be a valid email"
}
]
}
Common Error Codes
| Code | Meaning | Action |
|---|---|---|
INVALID_CREDENTIALS | Wrong email/password | Check credentials |
TOKEN_EXPIRED | Access token expired | Refresh token |
FORBIDDEN | Missing permission | Check user's groups |
USER_EMAIL_DUPLICATE | Email already exists | Use different email |
Handling Errors
try {
const response = await fetch('/v1/users', {
headers: { 'Authorization': `Bearer ${token}` }
});
if (!response.ok) {
const error = await response.json();
if (response.status === 401) {
// Refresh token or redirect to login
} else if (response.status === 422) {
// Show validation errors to user
console.error(error.errors);
} else {
// Show generic error message
console.error(error.error);
}
}
return await response.json();
} catch (err) {
// Network error or API unreachable
console.error('Network error:', err);
}