Spaces:
Sleeping
Sleeping
File size: 2,361 Bytes
72fc0ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """
QuantLib Pro SDK β Typed Exception Hierarchy
Exception Design:
QuantLibError (base)
βββ QuantLibAPIError # 4xx/5xx API responses
β βββ QuantLibAuthError # 401/403
β βββ QuantLibNotFoundError # 404
β βββ QuantLibRateLimitError # 429
βββ QuantLibNetworkError # Connection/timeout errors
βββ QuantLibValidationError # Request validation failures
"""
class QuantLibError(Exception):
"""Base exception for all QuantLib SDK errors."""
def __init__(self, message: str, *, status_code: int = 0, response: dict = None):
super().__init__(message)
self.status_code = status_code
self.response = response or {}
def __repr__(self):
return f"{self.__class__.__name__}(status={self.status_code}, message={str(self)})"
class QuantLibAPIError(QuantLibError):
"""Raised when the API returns a 4xx or 5xx status code."""
pass
class QuantLibAuthError(QuantLibAPIError):
"""Raised on 401 Unauthorized or 403 Forbidden responses."""
def __init__(self, message: str = "Authentication failed. Check credentials or token expiry."):
super().__init__(message, status_code=401)
class QuantLibNotFoundError(QuantLibAPIError):
"""Raised when the requested resource returns 404."""
def __init__(self, resource: str = "resource"):
super().__init__(f"Not found: {resource}", status_code=404)
class QuantLibRateLimitError(QuantLibAPIError):
"""Raised on 429 Too Many Requests. Contains retry_after seconds."""
def __init__(self, retry_after: int = 60):
super().__init__(
f"Rate limit exceeded. Retry after {retry_after} seconds.",
status_code=429,
)
self.retry_after = retry_after
class QuantLibNetworkError(QuantLibError):
"""Raised when the HTTP request fails due to network issues (timeout, DNS, etc.)."""
def __init__(self, message: str = "Network error. Check that the API server is running."):
super().__init__(message, status_code=0)
class QuantLibValidationError(QuantLibError):
"""Raised when request parameters fail Pydantic validation before sending."""
def __init__(self, field: str, message: str):
super().__init__(f"Validation error on field '{field}': {message}")
self.field = field
|