vectorize_client.exceptions

Vectorize API (Beta)

API for Vectorize services

The version of the OpenAPI document: 0.0.1 Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.

  1# coding: utf-8
  2
  3"""
  4    Vectorize API (Beta)
  5
  6    API for Vectorize services
  7
  8    The version of the OpenAPI document: 0.0.1
  9    Generated by OpenAPI Generator (https://openapi-generator.tech)
 10
 11    Do not edit the class manually.
 12"""  # noqa: E501
 13
 14from typing import Any, Optional
 15from typing_extensions import Self
 16
 17class OpenApiException(Exception):
 18    """The base exception class for all OpenAPIExceptions"""
 19
 20
 21class ApiTypeError(OpenApiException, TypeError):
 22    def __init__(self, msg, path_to_item=None, valid_classes=None,
 23                 key_type=None) -> None:
 24        """ Raises an exception for TypeErrors
 25
 26        Args:
 27            msg (str): the exception message
 28
 29        Keyword Args:
 30            path_to_item (list): a list of keys an indices to get to the
 31                                 current_item
 32                                 None if unset
 33            valid_classes (tuple): the primitive classes that current item
 34                                   should be an instance of
 35                                   None if unset
 36            key_type (bool): False if our value is a value in a dict
 37                             True if it is a key in a dict
 38                             False if our item is an item in a list
 39                             None if unset
 40        """
 41        self.path_to_item = path_to_item
 42        self.valid_classes = valid_classes
 43        self.key_type = key_type
 44        full_msg = msg
 45        if path_to_item:
 46            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
 47        super(ApiTypeError, self).__init__(full_msg)
 48
 49
 50class ApiValueError(OpenApiException, ValueError):
 51    def __init__(self, msg, path_to_item=None) -> None:
 52        """
 53        Args:
 54            msg (str): the exception message
 55
 56        Keyword Args:
 57            path_to_item (list) the path to the exception in the
 58                received_data dict. None if unset
 59        """
 60
 61        self.path_to_item = path_to_item
 62        full_msg = msg
 63        if path_to_item:
 64            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
 65        super(ApiValueError, self).__init__(full_msg)
 66
 67
 68class ApiAttributeError(OpenApiException, AttributeError):
 69    def __init__(self, msg, path_to_item=None) -> None:
 70        """
 71        Raised when an attribute reference or assignment fails.
 72
 73        Args:
 74            msg (str): the exception message
 75
 76        Keyword Args:
 77            path_to_item (None/list) the path to the exception in the
 78                received_data dict
 79        """
 80        self.path_to_item = path_to_item
 81        full_msg = msg
 82        if path_to_item:
 83            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
 84        super(ApiAttributeError, self).__init__(full_msg)
 85
 86
 87class ApiKeyError(OpenApiException, KeyError):
 88    def __init__(self, msg, path_to_item=None) -> None:
 89        """
 90        Args:
 91            msg (str): the exception message
 92
 93        Keyword Args:
 94            path_to_item (None/list) the path to the exception in the
 95                received_data dict
 96        """
 97        self.path_to_item = path_to_item
 98        full_msg = msg
 99        if path_to_item:
100            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
101        super(ApiKeyError, self).__init__(full_msg)
102
103
104class ApiException(OpenApiException):
105
106    def __init__(
107        self, 
108        status=None, 
109        reason=None, 
110        http_resp=None,
111        *,
112        body: Optional[str] = None,
113        data: Optional[Any] = None,
114    ) -> None:
115        self.status = status
116        self.reason = reason
117        self.body = body
118        self.data = data
119        self.headers = None
120
121        if http_resp:
122            if self.status is None:
123                self.status = http_resp.status
124            if self.reason is None:
125                self.reason = http_resp.reason
126            if self.body is None:
127                try:
128                    self.body = http_resp.data.decode('utf-8')
129                except Exception:
130                    pass
131            self.headers = http_resp.getheaders()
132
133    @classmethod
134    def from_response(
135        cls, 
136        *, 
137        http_resp, 
138        body: Optional[str], 
139        data: Optional[Any],
140    ) -> Self:
141        if http_resp.status == 400:
142            raise BadRequestException(http_resp=http_resp, body=body, data=data)
143
144        if http_resp.status == 401:
145            raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
146
147        if http_resp.status == 403:
148            raise ForbiddenException(http_resp=http_resp, body=body, data=data)
149
150        if http_resp.status == 404:
151            raise NotFoundException(http_resp=http_resp, body=body, data=data)
152
153        # Added new conditions for 409 and 422
154        if http_resp.status == 409:
155            raise ConflictException(http_resp=http_resp, body=body, data=data)
156
157        if http_resp.status == 422:
158            raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
159
160        if 500 <= http_resp.status <= 599:
161            raise ServiceException(http_resp=http_resp, body=body, data=data)
162        raise ApiException(http_resp=http_resp, body=body, data=data)
163
164    def __str__(self):
165        """Custom error messages for exception"""
166        error_message = "({0})\n"\
167                        "Reason: {1}\n".format(self.status, self.reason)
168        if self.headers:
169            error_message += "HTTP response headers: {0}\n".format(
170                self.headers)
171
172        if self.data or self.body:
173            error_message += "HTTP response body: {0}\n".format(self.data or self.body)
174
175        return error_message
176
177
178class BadRequestException(ApiException):
179    pass
180
181
182class NotFoundException(ApiException):
183    pass
184
185
186class UnauthorizedException(ApiException):
187    pass
188
189
190class ForbiddenException(ApiException):
191    pass
192
193
194class ServiceException(ApiException):
195    pass
196
197
198class ConflictException(ApiException):
199    """Exception for HTTP 409 Conflict."""
200    pass
201
202
203class UnprocessableEntityException(ApiException):
204    """Exception for HTTP 422 Unprocessable Entity."""
205    pass
206
207
208def render_path(path_to_item):
209    """Returns a string representation of a path"""
210    result = ""
211    for pth in path_to_item:
212        if isinstance(pth, int):
213            result += "[{0}]".format(pth)
214        else:
215            result += "['{0}']".format(pth)
216    return result
class OpenApiException(builtins.Exception):
18class OpenApiException(Exception):
19    """The base exception class for all OpenAPIExceptions"""

The base exception class for all OpenAPIExceptions

class ApiTypeError(OpenApiException, builtins.TypeError):
22class ApiTypeError(OpenApiException, TypeError):
23    def __init__(self, msg, path_to_item=None, valid_classes=None,
24                 key_type=None) -> None:
25        """ Raises an exception for TypeErrors
26
27        Args:
28            msg (str): the exception message
29
30        Keyword Args:
31            path_to_item (list): a list of keys an indices to get to the
32                                 current_item
33                                 None if unset
34            valid_classes (tuple): the primitive classes that current item
35                                   should be an instance of
36                                   None if unset
37            key_type (bool): False if our value is a value in a dict
38                             True if it is a key in a dict
39                             False if our item is an item in a list
40                             None if unset
41        """
42        self.path_to_item = path_to_item
43        self.valid_classes = valid_classes
44        self.key_type = key_type
45        full_msg = msg
46        if path_to_item:
47            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
48        super(ApiTypeError, self).__init__(full_msg)

The base exception class for all OpenAPIExceptions

ApiTypeError(msg, path_to_item=None, valid_classes=None, key_type=None)
23    def __init__(self, msg, path_to_item=None, valid_classes=None,
24                 key_type=None) -> None:
25        """ Raises an exception for TypeErrors
26
27        Args:
28            msg (str): the exception message
29
30        Keyword Args:
31            path_to_item (list): a list of keys an indices to get to the
32                                 current_item
33                                 None if unset
34            valid_classes (tuple): the primitive classes that current item
35                                   should be an instance of
36                                   None if unset
37            key_type (bool): False if our value is a value in a dict
38                             True if it is a key in a dict
39                             False if our item is an item in a list
40                             None if unset
41        """
42        self.path_to_item = path_to_item
43        self.valid_classes = valid_classes
44        self.key_type = key_type
45        full_msg = msg
46        if path_to_item:
47            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
48        super(ApiTypeError, self).__init__(full_msg)

Raises an exception for TypeErrors

Args: msg (str): the exception message

Keyword Args: path_to_item (list): a list of keys an indices to get to the current_item None if unset valid_classes (tuple): the primitive classes that current item should be an instance of None if unset key_type (bool): False if our value is a value in a dict True if it is a key in a dict False if our item is an item in a list None if unset

path_to_item
valid_classes
key_type
class ApiValueError(OpenApiException, builtins.ValueError):
51class ApiValueError(OpenApiException, ValueError):
52    def __init__(self, msg, path_to_item=None) -> None:
53        """
54        Args:
55            msg (str): the exception message
56
57        Keyword Args:
58            path_to_item (list) the path to the exception in the
59                received_data dict. None if unset
60        """
61
62        self.path_to_item = path_to_item
63        full_msg = msg
64        if path_to_item:
65            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
66        super(ApiValueError, self).__init__(full_msg)

The base exception class for all OpenAPIExceptions

ApiValueError(msg, path_to_item=None)
52    def __init__(self, msg, path_to_item=None) -> None:
53        """
54        Args:
55            msg (str): the exception message
56
57        Keyword Args:
58            path_to_item (list) the path to the exception in the
59                received_data dict. None if unset
60        """
61
62        self.path_to_item = path_to_item
63        full_msg = msg
64        if path_to_item:
65            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
66        super(ApiValueError, self).__init__(full_msg)

Args: msg (str): the exception message

Keyword Args: path_to_item (list) the path to the exception in the received_data dict. None if unset

path_to_item
class ApiAttributeError(OpenApiException, builtins.AttributeError):
69class ApiAttributeError(OpenApiException, AttributeError):
70    def __init__(self, msg, path_to_item=None) -> None:
71        """
72        Raised when an attribute reference or assignment fails.
73
74        Args:
75            msg (str): the exception message
76
77        Keyword Args:
78            path_to_item (None/list) the path to the exception in the
79                received_data dict
80        """
81        self.path_to_item = path_to_item
82        full_msg = msg
83        if path_to_item:
84            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
85        super(ApiAttributeError, self).__init__(full_msg)

The base exception class for all OpenAPIExceptions

ApiAttributeError(msg, path_to_item=None)
70    def __init__(self, msg, path_to_item=None) -> None:
71        """
72        Raised when an attribute reference or assignment fails.
73
74        Args:
75            msg (str): the exception message
76
77        Keyword Args:
78            path_to_item (None/list) the path to the exception in the
79                received_data dict
80        """
81        self.path_to_item = path_to_item
82        full_msg = msg
83        if path_to_item:
84            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
85        super(ApiAttributeError, self).__init__(full_msg)

Raised when an attribute reference or assignment fails.

Args: msg (str): the exception message

Keyword Args: path_to_item (None/list) the path to the exception in the received_data dict

path_to_item
class ApiKeyError(OpenApiException, builtins.KeyError):
 88class ApiKeyError(OpenApiException, KeyError):
 89    def __init__(self, msg, path_to_item=None) -> None:
 90        """
 91        Args:
 92            msg (str): the exception message
 93
 94        Keyword Args:
 95            path_to_item (None/list) the path to the exception in the
 96                received_data dict
 97        """
 98        self.path_to_item = path_to_item
 99        full_msg = msg
100        if path_to_item:
101            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
102        super(ApiKeyError, self).__init__(full_msg)

The base exception class for all OpenAPIExceptions

ApiKeyError(msg, path_to_item=None)
 89    def __init__(self, msg, path_to_item=None) -> None:
 90        """
 91        Args:
 92            msg (str): the exception message
 93
 94        Keyword Args:
 95            path_to_item (None/list) the path to the exception in the
 96                received_data dict
 97        """
 98        self.path_to_item = path_to_item
 99        full_msg = msg
100        if path_to_item:
101            full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
102        super(ApiKeyError, self).__init__(full_msg)

Args: msg (str): the exception message

Keyword Args: path_to_item (None/list) the path to the exception in the received_data dict

path_to_item
class ApiException(OpenApiException):
105class ApiException(OpenApiException):
106
107    def __init__(
108        self, 
109        status=None, 
110        reason=None, 
111        http_resp=None,
112        *,
113        body: Optional[str] = None,
114        data: Optional[Any] = None,
115    ) -> None:
116        self.status = status
117        self.reason = reason
118        self.body = body
119        self.data = data
120        self.headers = None
121
122        if http_resp:
123            if self.status is None:
124                self.status = http_resp.status
125            if self.reason is None:
126                self.reason = http_resp.reason
127            if self.body is None:
128                try:
129                    self.body = http_resp.data.decode('utf-8')
130                except Exception:
131                    pass
132            self.headers = http_resp.getheaders()
133
134    @classmethod
135    def from_response(
136        cls, 
137        *, 
138        http_resp, 
139        body: Optional[str], 
140        data: Optional[Any],
141    ) -> Self:
142        if http_resp.status == 400:
143            raise BadRequestException(http_resp=http_resp, body=body, data=data)
144
145        if http_resp.status == 401:
146            raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
147
148        if http_resp.status == 403:
149            raise ForbiddenException(http_resp=http_resp, body=body, data=data)
150
151        if http_resp.status == 404:
152            raise NotFoundException(http_resp=http_resp, body=body, data=data)
153
154        # Added new conditions for 409 and 422
155        if http_resp.status == 409:
156            raise ConflictException(http_resp=http_resp, body=body, data=data)
157
158        if http_resp.status == 422:
159            raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
160
161        if 500 <= http_resp.status <= 599:
162            raise ServiceException(http_resp=http_resp, body=body, data=data)
163        raise ApiException(http_resp=http_resp, body=body, data=data)
164
165    def __str__(self):
166        """Custom error messages for exception"""
167        error_message = "({0})\n"\
168                        "Reason: {1}\n".format(self.status, self.reason)
169        if self.headers:
170            error_message += "HTTP response headers: {0}\n".format(
171                self.headers)
172
173        if self.data or self.body:
174            error_message += "HTTP response body: {0}\n".format(self.data or self.body)
175
176        return error_message

The base exception class for all OpenAPIExceptions

ApiException( status=None, reason=None, http_resp=None, *, body: Optional[str] = None, data: Optional[Any] = None)
107    def __init__(
108        self, 
109        status=None, 
110        reason=None, 
111        http_resp=None,
112        *,
113        body: Optional[str] = None,
114        data: Optional[Any] = None,
115    ) -> None:
116        self.status = status
117        self.reason = reason
118        self.body = body
119        self.data = data
120        self.headers = None
121
122        if http_resp:
123            if self.status is None:
124                self.status = http_resp.status
125            if self.reason is None:
126                self.reason = http_resp.reason
127            if self.body is None:
128                try:
129                    self.body = http_resp.data.decode('utf-8')
130                except Exception:
131                    pass
132            self.headers = http_resp.getheaders()
status
reason
body
data
headers
@classmethod
def from_response(cls, *, http_resp, body: Optional[str], data: Optional[Any]) -> Self:
134    @classmethod
135    def from_response(
136        cls, 
137        *, 
138        http_resp, 
139        body: Optional[str], 
140        data: Optional[Any],
141    ) -> Self:
142        if http_resp.status == 400:
143            raise BadRequestException(http_resp=http_resp, body=body, data=data)
144
145        if http_resp.status == 401:
146            raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
147
148        if http_resp.status == 403:
149            raise ForbiddenException(http_resp=http_resp, body=body, data=data)
150
151        if http_resp.status == 404:
152            raise NotFoundException(http_resp=http_resp, body=body, data=data)
153
154        # Added new conditions for 409 and 422
155        if http_resp.status == 409:
156            raise ConflictException(http_resp=http_resp, body=body, data=data)
157
158        if http_resp.status == 422:
159            raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
160
161        if 500 <= http_resp.status <= 599:
162            raise ServiceException(http_resp=http_resp, body=body, data=data)
163        raise ApiException(http_resp=http_resp, body=body, data=data)
class BadRequestException(ApiException):
179class BadRequestException(ApiException):
180    pass

The base exception class for all OpenAPIExceptions

class NotFoundException(ApiException):
183class NotFoundException(ApiException):
184    pass

The base exception class for all OpenAPIExceptions

class UnauthorizedException(ApiException):
187class UnauthorizedException(ApiException):
188    pass

The base exception class for all OpenAPIExceptions

class ForbiddenException(ApiException):
191class ForbiddenException(ApiException):
192    pass

The base exception class for all OpenAPIExceptions

class ServiceException(ApiException):
195class ServiceException(ApiException):
196    pass

The base exception class for all OpenAPIExceptions

class ConflictException(ApiException):
199class ConflictException(ApiException):
200    """Exception for HTTP 409 Conflict."""
201    pass

Exception for HTTP 409 Conflict.

class UnprocessableEntityException(ApiException):
204class UnprocessableEntityException(ApiException):
205    """Exception for HTTP 422 Unprocessable Entity."""
206    pass

Exception for HTTP 422 Unprocessable Entity.

def render_path(path_to_item):
209def render_path(path_to_item):
210    """Returns a string representation of a path"""
211    result = ""
212    for pth in path_to_item:
213        if isinstance(pth, int):
214            result += "[{0}]".format(pth)
215        else:
216            result += "['{0}']".format(pth)
217    return result

Returns a string representation of a path