twitter-api-client icon indicating copy to clipboard operation
twitter-api-client copied to clipboard

If search.get hits a twitter rate limit, we get a JSONDecodeError

Open andylolz opened this issue 1 year ago • 0 comments

> await search.get(client, params)

Traceback (most recent call last):
  File "/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "<console>", line 1, in <module>
  File "/python3.10/site-packages/twitter/search.py", line 85, in get
    data = r.json()
  File "/python3.10/site-packages/httpx/_models.py", line 756, in json
    return jsonlib.loads(self.text, **kwargs)
  File "/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

It would be nice to raise a more self-explanatory exception in this circumstance, either via a custom exception, or by adding r.raise_for_status() around here: https://github.com/trevorhobenshield/twitter-api-client/blob/6847a525b3584131194ca398e3ae90f0dd36f87b/twitter/search.py#L84-L85

andylolz avatar Jul 15 '23 09:07 andylolz