error - Infernet Client
Description: Infernet Client Documentation

Skip to content

# Module: `error`

## `APIError`

Bases: `Exception`

Exception raised for errors during API calls.

Source code in `src/infernet_client/error.py`

     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
    class APIError(Exception):
        """Exception raised for errors during API calls."""

        def __init__(
            self,
            status_code: int,
            message: str = "Error occurred in API call",
            params: Optional[dict[str, Any]] = None,
        ):
            """
            Args:
                status_code (int): HTTP status code of the response
                message (str): explanation of the error
                params (dict[str, Any]): parameters used in the API call
            """
            self.status_code = status_code
            self.message = message
            self.params = params or {}
            super().__init__(self.message)

        def __str__(self) -> str:
            """
            Returns:
                str: string representation of the error
            """
            if self.params:
                params_str = ", ".join(
                    f"{key}={value}" for key, value in self.params.items()
                )
                return f"[{self.status_code}] {self.message} - [{params_str}]"
            else:
                return f"[{self.status_code}] {self.message}"

### `__init__(status_code, message='Error occurred in API call', params=None)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`status_code` | `int` | HTTP status code of the response | required
`message` | `str` | explanation of the error | `'Error occurred in API call'`
`params` | `dict[str, Any]` | parameters used in the API call | `None`

Source code in `src/infernet_client/error.py`

     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    def __init__(
        self,
        status_code: int,
        message: str = "Error occurred in API call",
        params: Optional[dict[str, Any]] = None,
    ):
        """
        Args:
            status_code (int): HTTP status code of the response
            message (str): explanation of the error
            params (dict[str, Any]): parameters used in the API call
        """
        self.status_code = status_code
        self.message = message
        self.params = params or {}
        super().__init__(self.message)

### `__str__()`

Returns:

Name | Type | Description
--- | --- | ---
`str` | `str` | string representation of the error

Source code in `src/infernet_client/error.py`

    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    def __str__(self) -> str:
        """
        Returns:
            str: string representation of the error
        """
        if self.params:
            params_str = ", ".join(
                f"{key}={value}" for key, value in self.params.items()
            )
            return f"[{self.status_code}] {self.message} - [{params_str}]"
        else:
            return f"[{self.status_code}] {self.message}"