Buckets:

download
raw
1.74 kB
"""LexyClient exception classes."""
from typing import Optional
import httpx
class LexyClientError(Exception):
"""Base exception class for LexyClient errors."""
def __init__(
self,
message: str,
response_data: Optional[dict] = None,
response: Optional[httpx.Response] = None,
):
super().__init__(message)
self.message = message
self.response_data = response_data
self.response = response
def __str__(self):
return f"{self.message}"
class LexyAPIError(LexyClientError):
"""Exception class for API errors."""
def __init__(
self, message: str = "Lexy API error", response: Optional[httpx.Response] = None
):
if response:
response_data = {
"status_code": response.status_code,
"text": response.text,
"url": response.url,
}
message = (
f"{message} "
f"'{response.status_code} {response.reason_phrase}' "
f"for url '{response.url}'\n"
f"\t{response.text}"
)
else:
response_data = None
super().__init__(message, response_data, response)
class NotFoundError(LexyAPIError):
"""Exception class for 404 errors."""
def __init__(
self, message: str = "Lexy API error", response: Optional[httpx.Response] = None
):
super().__init__(message, response)
def handle_response(response: httpx.Response) -> None:
"""Handle API response."""
if response.status_code == 404:
raise NotFoundError(response=response)
elif response.status_code >= 400:
raise LexyAPIError(response=response)

Xet Storage Details

Size:
1.74 kB
·
Xet hash:
9682e5e1c90dc068a8278c0882c3adca6fd7a1b26664ce9ffa88a7f160cb9a51

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.