| 1 |
|
| 2 |
|
| 3 |
from typing import Any, Dict, Optional |
| 4 |
|
| 5 |
|
| 6 |
class ParsingError(Exception): |
| 7 |
""" |
| 8 |
Raised when the SDK fails to parse/validate a response from the server. |
| 9 |
This typically indicates that the server returned a response whose shape |
| 10 |
does not match the expected schema. |
| 11 |
""" |
| 12 |
|
| 13 |
headers: Optional[Dict[str, str]] |
| 14 |
status_code: Optional[int] |
| 15 |
body: Any |
| 16 |
cause: Optional[Exception] |
| 17 |
|
| 18 |
def __init__( |
| 19 |
self, |
| 20 |
*, |
| 21 |
headers: Optional[Dict[str, str]] = None, |
| 22 |
status_code: Optional[int] = None, |
| 23 |
body: Any = None, |
| 24 |
cause: Optional[Exception] = None, |
| 25 |
) -> None: |
| 26 |
self.headers = headers |
| 27 |
self.status_code = status_code |
| 28 |
self.body = body |
| 29 |
self.cause = cause |
| 30 |
super().__init__() |
| 31 |
if cause is not None: |
| 32 |
self.__cause__ = cause |
| 33 |
|
| 34 |
def __str__(self) -> str: |
| 35 |
cause_str = f", cause: {self.cause}" if self.cause is not None else "" |
| 36 |
return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}{cause_str}" |