Exceptions
Exception Hierarchy
All HFortix-Core exceptions inherit from FortinetError:
FortinetError
├── AuthenticationError (HTTP 401)
├── AuthorizationError (HTTP 403)
├── ValidationError
├── ConfigurationError
├── VDOMError
├── OperationNotSupportedError
├── ReadOnlyModeError
├── CircuitBreakerError
│ └── CircuitBreakerTimeoutError
└── APIError
├── RetryableError
│ ├── RateLimitError (HTTP 429)
│ │ ├── RateLimitExceededError
│ │ ├── RateLimitQueueFullError
│ │ └── RateLimitQueueTimeoutError
│ ├── ServerError (HTTP 500)
│ ├── ServiceUnavailableError (HTTP 503)
│ ├── CircuitBreakerOpenError
│ └── TimeoutError
└── NonRetryableError
├── BadRequestError (HTTP 400)
├── ResourceNotFoundError (HTTP 404)
├── MethodNotAllowedError (HTTP 405)
├── DuplicateEntryError (error code -5, ...)
├── EntryInUseError (error code -23, ...)
├── InvalidValueError (error code -651, ...)
└── PermissionDeniedError (error code -14, -37)
Warning
AuthenticationError and AuthorizationError inherit directly from
FortinetError — not from APIError. An except APIError:
handler will not catch authentication/authorization failures; catch
them explicitly or use except FortinetError:.
All exceptions expose a message property that returns the original error
message without the extra context that str(exception) may include:
from hfortix_core import APIError
try:
...
except APIError as e:
print(e.message) # original message only
print(e) # message plus endpoint/status/hint context
Base Exception
API Exceptions
- exception hfortix_core.exceptions.RateLimitExceededError(message='Rate limit exceeded - request rejected', **kwargs)[source]
Bases:
RateLimitErrorRate limiter rejected request - limit exceeded (strategy=’raise’)
Configuration & Operation Exceptions
Retry & Circuit Breaker Exceptions
- exception hfortix_core.exceptions.CircuitBreakerError(message='Circuit breaker error', **kwargs)[source]
Bases:
FortinetErrorBase class for circuit breaker specific errors
- exception hfortix_core.exceptions.CircuitBreakerTimeoutError(message='Circuit breaker test calls timed out', **kwargs)[source]
Bases:
CircuitBreakerErrorCircuit breaker test calls timed out in half-open state
Helper Functions
These helpers live in the hfortix_core.exceptions module:
- hfortix_core.exceptions.raise_for_status(response, endpoint=None, method=None, params=None)[source]
Raise appropriate exception based on FortiOS API response
- Parameters:
- Raises:
APIError – If response indicates an error
- Return type:
Examples
>>> response = {'status': 'error', 'http_status': 404, 'error': -3} >>> raise_for_status( ... response, ... endpoint='/api/v2/cmdb/firewall/address', ... method='GET' ... ) # Raises ResourceNotFoundError with helpful context and tip
- hfortix_core.exceptions.is_retryable_error(error)[source]
Check if error should trigger automatic retry
- Parameters:
error (
Exception) – Exception to check- Return type:
- Returns:
True if error is retryable, False otherwise
Example
>>> try: ... fgt.api.cmdb.firewall.policy.get() ... except Exception as e: ... if is_retryable_error(e): ... time.sleep(5) ... # retry logic here
- hfortix_core.exceptions.get_retry_delay(error, attempt, base_delay=1.0, max_delay=60.0)[source]
Calculate appropriate retry delay based on error type and attempt number
- Parameters:
- Return type:
- Returns:
Recommended delay in seconds
Example
>>> for attempt in range(1, 4): ... try: ... result = fgt.api.cmdb.firewall.policy.get() ... break ... except Exception as e: ... if is_retryable_error(e): ... delay = get_retry_delay(e, attempt) ... time.sleep(delay) ... else: ... raise
- hfortix_core.exceptions.get_error_description(error_code)[source]
Get human-readable description for FortiOS error code
- Parameters:
error_code (int) – FortiOS error code
- Returns:
Error description or “Unknown error”
- Return type:
Examples
>>> get_error_description(-5) 'A duplicate entry already exists' >>> get_error_description(-651) 'Input value is invalid'