Error Handling
The RiverGen API uses a standardized error format to help you diagnose and resolve issues quickly.
Standard Error Format
All API errors return a JSON object with an error field:
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error message",
"details": {
"field": "parameter_name",
"reason": "Validation failed"
},
"timestamp": "2024-01-15T10:30:00Z"
}
}
Common Error Codes
| Code | HTTP Status | Description | Action |
|---|---|---|---|
AUTH_REQUIRED | 401 | No authentication token provided. | Provide a valid JWT in the Authorization header. |
AUTH_INVALID | 401 | Invalid or malformed authentication token. | Check your token for correctness. |
AUTH_EXPIRED | 401 | Authentication token has expired. | Refresh your token using the authentication endpoint. |
PERMISSION_DENIED | 403 | Authenticated user lacks necessary permissions. | Check user roles and required permissions for the endpoint. |
VALIDATION_ERROR | 400 | Request payload or query parameters are invalid. | Review the error details for specific field validation failures. |
RESOURCE_NOT_FOUND | 404 | The requested resource does not exist. | Verify the resource ID (e.g., river_id, project_id) is correct. |
RATE_LIMIT_EXCEEDED | 429 | Too many requests in a given time period. | Implement exponential backoff and respect X-RateLimit-Reset header. |
INTERNAL_ERROR | 500 | An unexpected server error occurred. | Report to support with timestamp and request_id (if available). |
SERVICE_UNAVAILABLE | 503 | The service is temporarily unable to handle the request. | Retry after a short delay. |
CONFLICT | 409 | A resource conflict occurred (e.g., duplicate entry). | Adjust your request to resolve the conflict (e.g., unique name). |
Example Error Responses
401 Unauthorized
{
"error": {
"code": "AUTH_INVALID",
"message": "Invalid authentication credentials",
"timestamp": "2024-01-15T10:30:00Z"
}
}
400 Bad Request
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": {
"field": "parameters.length",
"reason": "Value must be greater than 0"
},
"timestamp": "2024-01-15T10:30:00Z"
}
}
404 Not Found
{
"error": {
"code": "RESOURCE_NOT_FOUND",
"message": "River not found",
"details": {
"resource_type": "river",
"resource_id": "river_123"
},
"timestamp": "2024-01-15T10:30:00Z"
}
}
429 Too Many Requests
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Try again later.",
"timestamp": "2024-01-15T10:30:00Z"
}
}
Troubleshooting Steps
- Check the
codeandmessage: These provide a high-level understanding of the error. - Examine
details: For validation errors,detailswill pinpoint specific fields and reasons. - Review HTTP Status Code: This gives a general indication of the error category (e.g., 4xx for client errors, 5xx for server errors).
- Consult Documentation: Refer to the specific endpoint's documentation for expected request/response formats and common errors.
- Rate Limit Considerations: If you receive a 429 error:
- Check
X-RateLimit-Resetheader for when you can retry - Implement exponential backoff
- Reduce request frequency
- Check
See Also
- User Management API - API Reference
- Rate Limiting - Understanding rate limits
- Authentication - Token management