Error Handling
The NodeGet project API uses a unified error handling mechanism to ensure all RPC calls provide consistent error response formats.
Error Response Format
All API errors follow this JSON structure:
{
"error": {
"code": <error_code>,
"message": "<error_message>",
"data": <optional_error_data>
}
}NodegetError Enum
NodeGet defines a unified error enum NodegetError with the following error types:
Error Types
ParseError(String) - Parse Error (Error Code: 101)
- Thrown when request data parsing fails
PermissionDenied(String) - Permission Denied (Error Code: 102)
- Thrown when user doesn't have sufficient permissions to perform the operation
DatabaseError(String) - Database Error (Error Code: 103)
- Thrown when database operations fail
AgentConnectionError(String) - Agent Connection Error (Error Code: 104)
- Thrown when connection to agent nodes fails
NotFound(String) - Not Found (Error Code: 105)
- Thrown when requested resource doesn't exist
UuidNotFound(String) - UUID Not Found (Error Code: 106)
- Thrown when requested UUID doesn't exist
ConfigNotFound(String) - Config Not Found (Error Code: 107)
- Thrown when requested configuration doesn't exist
SerializationError(String) - Serialization Error (Error Code: 101)
- Thrown when data serialization/deserialization fails
IoError(String) - IO Error (Error Code: 101)
- Thrown when input/output operations fail
Other(String) - Other Error (Error Code: 999)
- Used for other uncategorized errors
JsonError Structure
To unify error response formats, NodeGet uses the JsonError structure:
pub struct JsonError {
pub error_id: i128, // Error code
pub error_message: String, // Error message
}Error Code Mapping
101- ParseError / SerializationError / IoError102- PermissionDenied103- DatabaseError104- AgentConnectionError105- NotFound106- UuidNotFound107- ConfigNotFound999- Other
Error Handling Examples
Success Response
{
"result": {
// Successful data
}
}Error Response
{
"error": {
"code": 102,
"message": "Permission denied: Insufficient permissions to read requested task types",
"data": null
}
}Error Handling Best Practices
- All RPC methods should return unified error formats
- Use appropriate error types to provide clear error information
- Include sufficient context in error messages for debugging
- Sensitive information should not be exposed in error messages
