Overview
The Imagen SDK provides a hierarchy of exception classes to help you handle different types of errors that may occur during API operations. All exceptions inherit from the baseImagenError class, allowing you to catch all SDK-related errors with a single exception handler or handle specific error types individually.
Exception Hierarchy
Import
Exception Classes
ImagenError
Base exception class for all Imagen SDK errors. Inheritance:Exception
Description: This is the parent class for all SDK-specific exceptions. Use this to catch any error originating from the Imagen SDK.
When raised: Never raised directly; only raised through its subclasses.
Example:
AuthenticationError
Raised when authentication fails. Inheritance:ImagenError
Description: This exception is raised when the API key is invalid, missing, or when access is unauthorized.
Common causes:
- Invalid or expired API key
- API key not activated by support
- Unauthorized access to resources
- Missing API key parameter
ProjectError
Raised when project operations fail. Inheritance:ImagenError
Description: This exception is raised when project-related operations encounter errors, such as project creation, editing, or export failures.
Common causes:
- Duplicate project name
- Project editing failures
- Export operation errors
- Invalid project UUID
- API errors during project operations
UploadError
Raised when upload operations fail. Inheritance:ImagenError
Description: This exception is raised when file uploads encounter errors, including validation failures and network issues.
Common causes:
- Mixed file types (RAW and JPEG in same project)
- Invalid file paths or missing files
- Unsupported file formats
- Network timeout or connection issues
- File validation failures
- Profile type mismatch (RAW profile with JPEG files)
DownloadError
Raised when download operations fail. Inheritance:ImagenError
Description: This exception is raised when downloading edited files or exports encounters errors.
Common causes:
- Expired download URLs
- Network connectivity issues
- Insufficient disk space
- Invalid output directory
- File permission errors
Comprehensive Error Handling
Complete Workflow with Error Handling
Step-by-Step Error Handling
Best Practices
- Always catch specific exceptions first, then fall back to the base
ImagenError - Use try-except blocks around each major operation for better error isolation
- Log errors with context to help with debugging
- Validate inputs before API calls to catch errors early
- Implement retry logic for network-related errors
- Provide helpful error messages to users
- Check disk space before large downloads
- Test API key validity before starting long workflows
Related
- See Error Handling Guide for more patterns
- Learn about File Formats to understand supported formats
- Review Installation for API key setup