Skip to content

exceptions

Exceptions for plisio.

PlisioAPIException

Bases: PlisioException

Plisio Exception.

Source code in src/plisio/exceptions.py
class PlisioAPIException(PlisioException):
    """
    Plisio Exception.
    """

    def __init__(self, response: _t.Response, status_code: int, text: str):
        """
        Constructor.

        Args:
            response (Response): Response.
            status_code (int): Status code.
            text (str): Text.
        """
        self.code = 0
        self.name = ""

        try:
            json_res = _loads(text)
        except ValueError:
            self.message = f"Invalid JSON error message from Plisio: {response.text}"
        else:
            data = json_res["data"]
            self.code = data["code"]
            self.message = data["message"]
            self.name = data["name"]

        self.response = response
        self.status_code = status_code
        self.request = getattr(response, "request", None)

    def __str__(self) -> str:
        """
        String representation.

        Returns:
            str: String representation.
        """

        return f"APIError(code={self.code}, name={self.name}): {self.message}"

__init__(response, status_code, text)

Constructor.

Parameters:

Name Type Description Default
response Response

Response.

required
status_code int

Status code.

required
text str

Text.

required
Source code in src/plisio/exceptions.py
def __init__(self, response: _t.Response, status_code: int, text: str):
    """
    Constructor.

    Args:
        response (Response): Response.
        status_code (int): Status code.
        text (str): Text.
    """
    self.code = 0
    self.name = ""

    try:
        json_res = _loads(text)
    except ValueError:
        self.message = f"Invalid JSON error message from Plisio: {response.text}"
    else:
        data = json_res["data"]
        self.code = data["code"]
        self.message = data["message"]
        self.name = data["name"]

    self.response = response
    self.status_code = status_code
    self.request = getattr(response, "request", None)

__str__()

String representation.

Returns:

Name Type Description
str str

String representation.

Source code in src/plisio/exceptions.py
def __str__(self) -> str:
    """
    String representation.

    Returns:
        str: String representation.
    """

    return f"APIError(code={self.code}, name={self.name}): {self.message}"

PlisioException

Bases: Exception

Plisio Exception.

Source code in src/plisio/exceptions.py
class PlisioException(Exception):
    """
    Plisio Exception.
    """

PlisioRequestException

Bases: PlisioException

Plisio Request Exception.

Source code in src/plisio/exceptions.py
class PlisioRequestException(PlisioException):
    """
    Plisio Request Exception.
    """

    def __init__(self, message: str):
        """
        Constructor.

        Args:
            message (str): Message.
        """

        self.message = message

    def __str__(self) -> str:
        """
        String representation.

        Returns:
            str: String representation.
        """

        return f"PlisioRequestException: {self.message}"

__init__(message)

Constructor.

Parameters:

Name Type Description Default
message str

Message.

required
Source code in src/plisio/exceptions.py
def __init__(self, message: str):
    """
    Constructor.

    Args:
        message (str): Message.
    """

    self.message = message

__str__()

String representation.

Returns:

Name Type Description
str str

String representation.

Source code in src/plisio/exceptions.py
def __str__(self) -> str:
    """
    String representation.

    Returns:
        str: String representation.
    """

    return f"PlisioRequestException: {self.message}"