Error Handling and Troubleshooting
The OcularAI SDK provides comprehensive error handling capabilities to help you diagnose and address issues in your applications. This guide explains the available error types and best practices for handling them effectively.Error Hierarchy
All SDK errors inherit from the base
OcularError
class, making it easy to catch any SDK-related issue.OcularError
class, allowing you to catch all SDK-specific errors with a single exception handler:
Specific Error Types
Using specific error types allows you to implement targeted error handling strategies in your application.
Error Type | Description | Common Causes |
---|---|---|
AuthenticationError | Issues with authentication | Invalid API key, expired credentials |
ValidationError | Invalid parameters or inputs | Incorrect ID format, missing required fields |
ResourceNotFoundError | Requested resource not found | Non-existent workspace, project, version, or export |
RateLimitError | API rate limits exceeded | Too many requests in a short period |
ServerError | Server-side errors | Internal server issues, maintenance |
NetworkError | Network connectivity issues | Connection problems, timeouts |
TimeoutError | Request timeout | Slow network, large dataset downloads |
Example: Handling Specific Error Types
You can catch specific error types to handle different error scenarios differently:Retry Mechanism
For operations that might be affected by transient network issues, configuring proper retry settings can significantly improve reliability.
Debug Mode
Debug mode provides detailed logs that are invaluable when troubleshooting issues with the SDK.
Common Error Scenarios and Solutions
Being familiar with these common error scenarios can save significant troubleshooting time during development.
Scenario | Error | Solution |
---|---|---|
Invalid API Key | AuthenticationError | Check that your API key is correct and has the necessary permissions |
Incorrect Workspace/Project ID | ResourceNotFoundError | Verify the IDs in the OcularAI Foundry platform |
Slow Downloads | TimeoutError | Increase the timeout setting or use a more reliable network |
”Too Many Requests” error | RateLimitError | Implement exponential backoff, reduce request frequency |
Server Maintenance | ServerError | Wait and retry after some time |
Logging and Debugging
Proper logging configuration is essential for production applications to help diagnose issues that occur in deployed environments.