MCPcopy Index your code
hub / github.com/praw-dev/praw / parse_error

Method parse_error

praw/objector.py:27–48  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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.

Callers 2

check_errorMethod · 0.80
test_parse_errorMethod · 0.80

Calls 3

ClientExceptionClass · 0.90
RedditAPIExceptionClass · 0.90
getMethod · 0.80

Tested by 1

test_parse_errorMethod · 0.64