Error Handling and Validation
Building Robust Handlers with Comprehensive Error Management
Introduction
RPC Error Codes
Standard Error Codes
// Parameter validation errors
rpcINVALID_PARAMS // Invalid or missing parameters
rpcBAD_SYNTAX // Malformed request structure
rpcINVALID_API_VERSION // Requested API version not supported
// Authentication/Permission errors
rpcNO_PERMISSION // Insufficient role for operation
rpcFORBIDDEN // Client IP blacklisted
rpcBAD_AUTH_MASTER // Master key authentication failed
rpcBAD_AUTH_TOKEN // Token authentication failed
// Ledger-related errors
rpcNO_CURRENT // No current (open) ledger available
rpcNO_CLOSED // No closed (validated) ledger available
rpcLGR_NOT_FOUND // Specified ledger not found
rpcLGR_IDXS_NOTFND // Ledger indices not found
rpcLGR_INDEX_BOUNDS // Ledger index out of valid range
// Account-related errors
rpcACT_NOT_FOUND // Account not found in ledger
rpcACT_MALFORMED // Account address malformed
rpcDUPLICATE // Duplicate account in request
// Transaction-related errors
rpcTXN_NOT_FOUND // Transaction not found
rpcTXN_FAILED // Transaction validation failed
rpcMASTER_DISABLED // Master key disabled on account
rpcINSUFFICIENT_FUNDS // Insufficient funds for operation
// Network/Server errors
rpcNO_NETWORK // Node not connected to network
rpcCOMMAND_UNIMPLEMENTED // Command not implemented
rpcUNKNOWN_COMMAND // Unknown RPC command
rpcINTERNAL // Internal server error
rpcSLOW_DOWN // Rate limited - too many requestsComplete Error Code List
HTTP Status Code Mapping
Mapping Strategy
Example HTTP Response
Error Response Formatting
Standard Error Response Structure
Building Error Responses in Code
Input Validation Patterns
Validate Required Fields
Validate Numeric Ranges
Validate Addresses and Identifiers
Validate Enum/Choice Parameters
Validate Optional Fields
Sensitive Data Masking
Protect Private Keys and Secrets
Sanitize Error Messages
Mask Sensitive Request Data
Exception Handling
Catch Exceptions in Handlers
Standard Exception Types
Comprehensive Validation Example
Validation Best Practices
✅ DO
❌ DON'T
Common Validation Scenarios
Scenario 1: Currency/Amount Handling
Scenario 2: Ledger Index Selection
Scenario 3: Pagination Validation
Conclusion
PreviousAuthentication and AuthorizationNextCommunication II: Building and Integrating Custom RPC Handlers
Last updated

