Skip to content

Commit 6a0f49b

Browse files
authored
Merge pull request #518 from github/jm_api_error_message_handling
feat: pass through api error messages
2 parents 0bac475 + 748a5f0 commit 6a0f49b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

search.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,50 @@ def wait_for_api_refresh(
8080
if idx % issues_per_page == 0:
8181
wait_for_api_refresh(issues_iterator, rate_limit_bypass)
8282

83-
except github3.exceptions.ForbiddenError:
83+
except github3.exceptions.ForbiddenError as e:
8484
print(
8585
f"You do not have permission to view a repository \
8686
from: '{repos_and_owners_string}'; Check your API Token."
8787
)
88+
print_error_messages(e)
8889
sys.exit(1)
89-
except github3.exceptions.NotFoundError:
90+
except github3.exceptions.NotFoundError as e:
9091
print(
9192
f"The repository could not be found; \
9293
Check the repository owner and names: '{repos_and_owners_string}"
9394
)
95+
print_error_messages(e)
9496
sys.exit(1)
95-
except github3.exceptions.ConnectionError:
97+
except github3.exceptions.ConnectionError as e:
9698
print(
9799
"There was a connection error; Check your internet connection or API Token."
98100
)
101+
print_error_messages(e)
99102
sys.exit(1)
100-
except github3.exceptions.AuthenticationFailed:
103+
except github3.exceptions.AuthenticationFailed as e:
101104
print("Authentication failed; Check your API Token.")
105+
print_error_messages(e)
102106
sys.exit(1)
103-
except github3.exceptions.UnprocessableEntity:
107+
except github3.exceptions.UnprocessableEntity as e:
104108
print("The search query is invalid; Check the search query.")
109+
print_error_messages(e)
105110
sys.exit(1)
106111

107112
return issues
108113

109114

115+
def print_error_messages(error: github3.exceptions):
116+
"""Prints the error messages from the GitHub API response.
117+
118+
Args:
119+
Error (github3.exceptions): The error object from the GitHub API response.
120+
121+
"""
122+
if hasattr(error, "errors"):
123+
for e in error.errors:
124+
print(f"Error: {e.get('message')}")
125+
126+
110127
def get_owners_and_repositories(
111128
search_query: str,
112129
) -> List[dict]:

0 commit comments

Comments
 (0)