MCPcopy Create free account
hub / github.com/devflowinc/trieve / ApiException

Class ApiException

clients/python-sdk/trieve_py_client/exceptions.py:105–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104
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 if 500 <= http_resp.status <= 599:
155 raise ServiceException(http_resp=http_resp, body=body, data=data)
156 raise ApiException(http_resp=http_resp, body=body, data=data)
157
158 def __str__(self):
159 """Custom error messages for exception"""
160 error_message = "({0})\n"\
161 "Reason: {1}\n".format(self.status, self.reason)
162 if self.headers:

Callers 2

requestMethod · 0.90
from_responseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected