Error Handling Guide
The Skribble SDK provides structured error handling with specific error types for different scenarios. This guide explains the error types and how to handle them effectively.
Error Types
Base Error
The base error class that all other SDK errors inherit from:
SkribbleError
# Properties:
# - message: str
Authentication Error
Thrown specifically for authentication failures:
try:
skribble.init(username="api_xxxxx", api_key="xxxxx")
except SkribbleAuthError as e:
print(f"Authentication failed: {e.message}")
API Error
Thrown when the Skribble API returns an error response:
try:
response = skribble.signature_request.create(request_data)
except SkribbleAPIError as e:
print(f"API Error: {e.message}")
print(f"Status Code: {e.status_code}")
Validation Error
Thrown for input validation failures:
try:
response = skribble.signature_request.create(invalid_data)
except SkribbleValidationError as e:
print(f"Validation Error: {e.message}")
for error in e.errors:
print(f"- {error['field']}: {error['msg']}")
Operation Error (Python Only)
Provides detailed context about operation failures:
try:
response = skribble.signature_request.create(request_data)
except SkribbleOperationError as e:
print(f"Operation '{e.operation}' failed: {e.message}")
if e.original_error:
print(f"Caused by: {str(e.original_error)}")
Error Handling Best Practices
Complete Error Handling
try:
response = skribble.signature_request.create(request_data)
except SkribbleAuthError as e:
# Handle authentication failures
print(f"Authentication failed: {e.message}")
except SkribbleValidationError as e:
# Handle validation errors
print(f"Invalid data: {e.message}")
for error in e.errors:
print(f"- {error['field']}: {error['msg']}")
except SkribbleAPIError as e:
# Handle API errors
print(f"API Error ({e.status_code}): {e.message}")
except SkribbleOperationError as e:
# Handle operation-specific errors
print(f"Operation '{e.operation}' failed: {e.message}")
except SkribbleError as e:
# Handle any other SDK errors
print(f"SDK Error: {e.message}")
Common Error Scenarios
Authentication Failures
try:
skribble.init(username="api_xxxxx", api_key="xxxxx")
except SkribbleAuthError as e:
# Handle authentication failure
print(f"Authentication failed: {e.message}")
# Prompt for new credentials or retry
Invalid Request Data
try:
response = skribble.signature_request.create({
"title": "", # Invalid: empty title
"signatures": [] # Invalid: no signers
})
except SkribbleValidationError as e:
print("Invalid request data:")
for error in e.errors:
print(f"- {error['field']}: {error['msg']}")
API Rate Limiting
try:
response = skribble.signature_request.create(request_data)
except SkribbleAPIError as e:
if e.status_code == 429:
# Handle rate limiting
print("Rate limit exceeded. Please wait before retrying.")
# Implement exponential backoff
Error Recovery Strategies
- Authentication Errors: Re-authenticate or refresh credentials
- Validation Errors: Fix the invalid data based on the error details
- API Errors: Handle based on status code (retry for 5xx, fix request for 4xx)
- Operation Errors: Log details and handle based on the specific operation
API Reference
For detailed API documentation, see: