Skip to content

Commit

Permalink
Error early with useful messages
Browse files Browse the repository at this point in the history
  • Loading branch information
glasnt committed Dec 8, 2020
1 parent c85e71d commit 59a3a73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 0 additions & 3 deletions octohatrack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 40,6 @@ def main():

progress_message("Checking repo exists")
repo = get_json("repos/%s" % repo_name)
if "message" in repo:
print("Repo does not exist: %s" % repo_name)
sys.exit(1)

progress_message("Getting API Contributors")
api = api_contributors(repo_name)
Expand Down
3 changes: 3 additions & 0 deletions octohatrack/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,9 @@ def get_json(uri):
"""
response = requests.get(API uri, headers=HEADERS)

if response.status_code != requests.codes.ok:
error_exit(response)

limit = int(response.headers.get("x-ratelimit-remaining"))
if limit == 0:
sys.stdout.write("\n")
Expand Down
16 changes: 16 additions & 0 deletions octohatrack/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 51,19 @@ def progress_message(message):
sys.stdout.write("\n")
sys.stdout.write("%s..." % message)
sys.stdout.flush()


def error_exit(response):
breakpoint()
message = response.json()["message"]
status = response.status_code
suggestion = None
if message == "Bad credentials" and status == 401:
suggestion = "Ensure you have set a GITHUB_TOKEN."

output = "\n\nError code " str(status) ": " message
if suggestion:
output = "\n" suggestion

print(output)
sys.exit(1)

0 comments on commit 59a3a73

Please sign in to comment.