Skip to content

feat: pass through api error messages #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,50 @@ def wait_for_api_refresh(
if idx % issues_per_page == 0:
wait_for_api_refresh(issues_iterator, rate_limit_bypass)

except github3.exceptions.ForbiddenError:
except github3.exceptions.ForbiddenError as e:
print(
f"You do not have permission to view a repository \
from: '{repos_and_owners_string}'; Check your API Token."
)
print_error_messages(e)
sys.exit(1)
except github3.exceptions.NotFoundError:
except github3.exceptions.NotFoundError as e:
print(
f"The repository could not be found; \
Check the repository owner and names: '{repos_and_owners_string}"
)
print_error_messages(e)
sys.exit(1)
except github3.exceptions.ConnectionError:
except github3.exceptions.ConnectionError as e:
print(
"There was a connection error; Check your internet connection or API Token."
)
print_error_messages(e)
sys.exit(1)
except github3.exceptions.AuthenticationFailed:
except github3.exceptions.AuthenticationFailed as e:
print("Authentication failed; Check your API Token.")
print_error_messages(e)
sys.exit(1)
except github3.exceptions.UnprocessableEntity:
except github3.exceptions.UnprocessableEntity as e:
print("The search query is invalid; Check the search query.")
print_error_messages(e)
sys.exit(1)

return issues


def print_error_messages(error: github3.exceptions):
"""Prints the error messages from the GitHub API response.

Args:
Error (github3.exceptions): The error object from the GitHub API response.

"""
if hasattr(error, "errors"):
for e in error.errors:
print(f"Error: {e.get('message')}")


def get_owners_and_repositories(
search_query: str,
) -> List[dict]:
Expand Down
Loading