Overview
The Mention SDK provides a hierarchy of exception classes to help you handle different types of errors gracefully. All exceptions inherit from the baseMentionError class, making it easy to catch all SDK-related errors or handle specific error types.
Exception Hierarchy
Exception Classes
MentionError
Base exception for all Mention API errors. All other exceptions inherit from this class. Properties:message(str): The error messagedetails(dict): Additional error details
- Base class for all SDK exceptions
- Can be used to catch all Mention SDK errors
MentionAPIError
Exception raised when the API returns an error response. Properties:message(str): The error messagestatus_code(int): HTTP status code from the API responseresponse_body(dict | str | None): The full response body from the APIdetails(dict): Containsstatus_codeandresponsekeys
- API returns a 4xx or 5xx status code
- Server errors or client errors not covered by specific subclasses
MentionAuthError
Exception raised for authentication and authorization errors (401, 403). Properties:- Inherits all properties from
MentionAPIError status_code(int): Will be 401 or 403
- Invalid or missing API key (401)
- Insufficient permissions to access a resource (403)
- Expired authentication token
MentionNotFoundError
Exception raised when a resource is not found (404). Properties:- Inherits all properties from
MentionAPIError status_code(int): Will be 404
- Requested resource doesn’t exist
- Invalid resource ID
- Resource was deleted
MentionRateLimitError
Exception raised when the API rate limit is exceeded (429). Properties:- Inherits all properties from
MentionAPIError status_code(int): Will be 429retry_after(int | None): Number of seconds to wait before retrying (if provided by API)
- Too many requests sent in a given time period
- API rate limit exceeded
MentionValidationError
Exception raised for request validation errors. Properties:- Inherits all properties from
MentionError message(str): Validation error descriptiondetails(dict): Additional validation error details
- Invalid parameter values
- Missing required parameters
- Data format validation failures
- Client-side validation errors before making API request
MentionConnectionError
Exception raised for network and connection errors. Properties:- Inherits all properties from
MentionError message(str): Connection error descriptiondetails(dict): Additional connection error details
- Network connectivity issues
- Timeout errors
- DNS resolution failures
- Connection refused errors
- SSL/TLS errors
Practical Error Handling Patterns
Catch All SDK Errors
Handle Specific Error Types
Retry Logic with Rate Limiting
Logging Errors for Debugging
Graceful Degradation
Best Practices
- Catch specific exceptions first: Order your except clauses from most specific to most general
- Always handle authentication errors: Check API keys and permissions when
MentionAuthErroroccurs - Respect rate limits: Use
retry_afterproperty fromMentionRateLimitErrorto implement proper backoff - Log error details: Include
status_code,response_body, anddetailsin your logs for debugging - Implement retry logic: Handle transient errors like
MentionConnectionErrorwith exponential backoff - Validate input early: Catch
MentionValidationErrorand provide user-friendly feedback - Use the base exception for catch-all: Use
MentionErrorto catch all SDK-related errors