Skip to main content

SDK Exceptions

The xpander.ai SDK provides a comprehensive exception system for handling errors gracefully. All SDK modules can raise specific exceptions that help you identify and handle different error conditions.

Core Exception Classes

ModuleException

The base exception class for all SDK-related errors. All other SDK exceptions inherit from this class.
Properties:
  • status_code (int): HTTP status code associated with the error
  • description (str): Human-readable error description
  • details (Optional[Dict[str, Any]]): Additional error details when available
Example:

Common Error Scenarios

Authentication Errors

Status Code: 401 (Unauthorized) Occurs when API key is missing, invalid, or expired.

Authorization Errors

Status Code: 403 (Forbidden) Occurs when you don’t have permission to access a resource.

Resource Not Found

Status Code: 404 (Not Found) Occurs when a requested resource doesn’t exist.

Validation Errors

Status Code: 400 (Bad Request) Occurs when request parameters are invalid or missing.

Rate Limiting

Status Code: 429 (Too Many Requests) Occurs when you exceed the API rate limits.

Server Errors

Status Code: 500+ (Server Error) Occurs when there’s an internal server error.

Error Handling Patterns

Basic Error Handling

Comprehensive Error Handling

Context Manager for Resource Cleanup

Retry Logic with Custom Conditions

Module-Specific Error Handling

Agents Module

Tasks Module

Tools Repository

Knowledge Bases

Best Practices

1. Always Handle ModuleException

2. Check Status Codes for Specific Handling

3. Use Appropriate Logging Levels

4. Provide Meaningful Error Messages

  • [Agents Module](/API reference/agents): Agent management and error handling
  • [Tasks Module](/API reference/tasks): Task execution and error handling
  • [Tools Repository](/API reference/tools): Tool integration and error handling
  • [Knowledge Bases](/API reference/knowledge): Knowledge base operations and error handling
  • [Configuration](/API reference/configuration): SDK configuration and authentication