About pagination of github.get
yiwu1 opened this issue · comments
@cenkalti Sounds great example! Do you have API reference document with detailed introduction about flask_github.GitHub.get ? As you know it only returns 30 records by default in first page, trying to leverage this method for all pagination records instead to write own.
If you pass all_pages=True
, the library will fetch all of the pages.
Line 250 in a65bae8
👍
@cenkalti When I call request(self, method, resource, all_pages=False, **kwargs), terminal console will get 404: not found if GitHub API return empty sometime, I know it goes to following lines:
if not is_valid_response(response):
raise GitHubError(response)
Is it possible to catch the GitHubError exception like 404, 409 ? And how to catch different exception so that I can do conditional check? for example
try: request()
except [how to get 404 here]: do something
Thanks!
You can capture GitHubError
and inspect status code attribute.
try:
...
except GitHubError as e:
if e.response.status_code == 404:
# handle 404
raise
@cenkalti Thanks for your reply! I tried but not work as expected here:
except GitHubError as e:
NameError: global name 'GitHubError' is not defined
Put it at the top of your file:
from flask_github import GitHubError
👍 ✨ 🎉