Overview
The Mention API SDK provides a comprehensive exception hierarchy and built-in retry mechanisms to help you build resilient applications. This guide covers all exception types, retry strategies, and best practices for error handling.Exception Hierarchy
All exceptions inherit fromMentionError, making it easy to catch all SDK-related errors:
Exception Types
MentionError
Base exception for all Mention SDK errors. Attributes:message(str): Human-readable error messagedetails(dict): Additional error details
MentionAPIError
Raised when the API returns an error response. Attributes:status_code(int): HTTP status coderesponse_body(dict | str | None): Raw response body from APImessage(str): Error messagedetails(dict): Additional details
MentionAuthError
Raised for authentication and authorization failures (401, 403). Attributes:status_code(int): 401 or 403response_body(dict | str | None): Error responsemessage(str): Authentication error message
MentionNotFoundError
Raised when a requested resource doesn’t exist (404). Attributes:status_code(int): 404response_body(dict | str | None): Error responsemessage(str): Not found error message
MentionRateLimitError
Raised when API rate limits are exceeded (429). Attributes:status_code(int): 429response_body(dict | str | None): Error responseretry_after(int | None): Seconds to wait before retrying (fromRetry-Afterheader)message(str): Rate limit error message
MentionValidationError
Raised for request validation errors (invalid parameters, missing required fields).MentionConnectionError
Raised for network and connection issues (timeouts, connection failures).Built-in Retry Logic
BothMentionClient and AsyncMentionClient include automatic retry logic with exponential backoff for transient failures.
Default Retry Behavior
- Max retries: 3 attempts (configurable)
- Retry delay: 1 second base delay (configurable)
- Backoff: Exponential (delay doubles each retry)
- Retried errors: Connection errors, timeouts, rate limits
Configuring Retries
- Sync
- Async
Rate Limit Handling
The client automatically respectsRetry-After headers for rate limit errors:
Error Handling Patterns
Basic Error Handling
Catch specific exceptions for targeted handling:- Sync
- Async
Custom Retry Logic
Implement your own retry logic with custom backoff strategies:Graceful Degradation
Handle errors gracefully without crashing:Logging Errors
Integrate with Python’s logging system:Best Practices
Catch Specific Exceptions First
Catch Specific Exceptions First
Order exception handlers from most specific to most general:
Don't Ignore Errors Silently
Don't Ignore Errors Silently
Always log or handle errors appropriately:
Implement Circuit Breaker Pattern
Implement Circuit Breaker Pattern
Prevent cascading failures with circuit breaker:
Set Appropriate Timeouts
Set Appropriate Timeouts
Configure timeouts based on your requirements:
Testing Error Handling
Test your error handling with mock failures:Next Steps
Pagination
Learn efficient pagination techniques
API Reference
Explore complete API documentation