Skip to content

Commit

Permalink
Modified some error messages (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpatel41 authored Jun 1, 2021
1 parent 6f76460 commit 36d54c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 12 additions & 5 deletions tap_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def rate_throttling(response):
seconds_to_sleep = calculate_seconds(int(response.headers['X-RateLimit-Reset']))

if seconds_to_sleep > 600:
raise RateLimitExceeded("API rate limit exceeded, please try after {} seconds.".format(seconds_to_sleep))
message = "API rate limit exceeded, please try after {} seconds.".format(seconds_to_sleep)
raise RateLimitExceeded(message) from None

logger.info("API rate limit exceeded. Tap will retry the data collection after %s seconds.", seconds_to_sleep)
time.sleep(seconds_to_sleep)
Expand Down Expand Up @@ -315,10 +316,16 @@ def verify_repo_access(url_for_repo, repo):
authed_get("verifying repository access", url_for_repo)
except NotFoundException:
# throwing user-friendly error message as it checks token access
raise NotFoundException("HTTP-error-code: 404, Error: Please check the repository name \'{}\' or you do not have sufficient permissions to access this repository.".format(repo)) from None
message = "HTTP-error-code: 404, Error: Please check the repository name \'{}\' or you do not have sufficient permissions to access this repository.".format(repo)
raise NotFoundException(message) from None

def verify_org_access(url_for_org):
authed_get("verifying repository access", url_for_org)
def verify_org_access(url_for_org, org):
try:
authed_get("verifying organization access", url_for_org)
except NotFoundException:
# throwing user-friendly error message as it shows "Not Found" message
message = "HTTP-error-code: 404, Error: \'{}\' is not an organization.".format(org)
raise NotFoundException(message) from None

def verify_access_for_repo_org(config):

Expand All @@ -337,7 +344,7 @@ def verify_access_for_repo_org(config):
# Verifying for Repo access
verify_repo_access(url_for_repo, repo)
# Verifying for Org access
verify_org_access(url_for_org)
verify_org_access(url_for_org, org)

def do_discover(config):
verify_access_for_repo_org(config)
Expand Down
10 changes: 5 additions & 5 deletions tests/unittests/test_verify_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def test_org_not_found(self, mocked_request):
mocked_request.return_value = get_response(404, json, True)

try:
tap_github.verify_org_access("")
tap_github.verify_org_access("", "personal-repo")
except tap_github.NotFoundException as e:
self.assertEquals(str(e), "HTTP-error-code: 404, Error: {}".format(json))
self.assertEquals(str(e), "HTTP-error-code: 404, Error: 'personal-repo' is not an organization.")

def test_org_bad_request(self, mocked_request):
mocked_request.return_value = get_response(400, raise_error = True)

try:
tap_github.verify_org_access("")
tap_github.verify_org_access("", "personal-repo")
except tap_github.BadRequestException as e:
self.assertEquals(str(e), "HTTP-error-code: 400, Error: The request is missing or has a bad parameter.")

Expand All @@ -73,7 +73,7 @@ def test_org_forbidden(self, mocked_request):
mocked_request.return_value = get_response(403, json, True)

try:
tap_github.verify_org_access("")
tap_github.verify_org_access("", "personal-repo")
except tap_github.AuthException as e:
self.assertEquals(str(e), "HTTP-error-code: 403, Error: {}".format(json))

Expand All @@ -82,7 +82,7 @@ def test_org_bad_creds(self, mocked_request):
mocked_request.return_value = get_response(401, json, True)

try:
tap_github.verify_org_access("")
tap_github.verify_org_access("", "personal-repo")
except tap_github.BadCredentialsException as e:
self.assertEquals(str(e), "HTTP-error-code: 401, Error: {}".format(json))

Expand Down

0 comments on commit 36d54c4

Please sign in to comment.