Convert JSON response into an error object. :param data: The dict to be converted. :returns: An instance of :class:`.RedditAPIException`, or ``None`` if ``data`` doesn't fit this model.
(cls, data: list[Any] | dict[str, Any])
| 25 | |
| 26 | @classmethod |
| 27 | def parse_error(cls, data: list[Any] | dict[str, Any]) -> RedditAPIException | None: |
| 28 | """Convert JSON response into an error object. |
| 29 | |
| 30 | :param data: The dict to be converted. |
| 31 | |
| 32 | :returns: An instance of :class:`.RedditAPIException`, or ``None`` if ``data`` |
| 33 | doesn't fit this model. |
| 34 | |
| 35 | """ |
| 36 | if isinstance(data, list): |
| 37 | # Fetching a Submission returns a list (of two items). Although it's handled |
| 38 | # manually in `Submission._fetch()`, assume it's a possibility here. |
| 39 | return None |
| 40 | |
| 41 | errors = data.get("json", {}).get("errors") |
| 42 | if errors is None: |
| 43 | return None |
| 44 | if len(errors) < 1: |
| 45 | # See `Collection._fetch()`. |
| 46 | msg = "successful error response" |
| 47 | raise ClientException(msg, data) |
| 48 | return RedditAPIException(errors) |
| 49 | |
| 50 | def __init__(self, reddit: praw.Reddit, parsers: dict[str, Any] | None = None) -> None: |
| 51 | """Initialize an :class:`.Objector` instance. |