Skip to content

errors

Api errors.

Classes:

Name Description
ApiError

Exception raised when an API request fails.

Functions:

Name Description
handle_api_validation_errors

Raise HTTPValidationError in case the call to API return such response.

ApiError(message: str) #

Exception raised when an API request fails.

Source code in src/xpdeep/utils/errors.py
def __init__(self, message: str) -> None:
    super().__init__(message)

handle_api_validation_errors(api_call_result: T | HTTPValidationError | None) -> T #

Raise HTTPValidationError in case the call to API return such response.

Source code in src/xpdeep/utils/errors.py
def handle_api_validation_errors[T](api_call_result: T | HTTPValidationError | None) -> T:
    """Raise HTTPValidationError in case the call to API return such response."""
    if isinstance(api_call_result, HTTPValidationError):
        message = f"A ValidationError occurred, make sure that API client is up to date : {api_call_result.detail}"
        raise ApiError(message)

    if api_call_result is None:
        message = "Something went wrong. Unexpected API response type."
        raise ApiError(message)

    return api_call_result