Error Handling

Exception types and how to handle failures from the Daita Client.

#Exception Types

python
from daita_client import (
    ExecutionError,        # Base class for all execution errors
    AuthenticationError,   # Invalid or missing API key
    NotFoundError,         # Agent, workflow, or execution not found
    ValidationError,       # Bad request data
    RateLimitError,        # API rate limit exceeded
    ExecutionTimeoutError, # wait_for_execution exceeded timeout
    ServerError,           # Unexpected server-side error
)

#Example

python
from daita_client import DaitaClient, ExecutionError, ExecutionTimeoutError, AuthenticationError
 
client = DaitaClient(api_key="your_api_key")
 
try:
    result = client.execute_agent("my_agent", data={}, wait=True, timeout=60)
    print(result.result)
 
except AuthenticationError:
    print("Check your DAITA_API_KEY")
 
except ExecutionTimeoutError:
    print("Agent did not complete within 60 seconds")
 
except ExecutionError as e:
    print(f"Execution failed: {e}")

#Execution Failures

If an agent itself fails during execution, the ExecutionResult status will be "failed" rather than raising an exception. Check result.error for the reason:

python
result = client.execute_agent("my_agent", data={}, wait=True)
 
if result.status == "failed":
    print(f"Agent failed: {result.error}")
else:
    print(result.result)