Skip to content
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

TDL-13115: Modified some error messages #121

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions tap_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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 @@ -313,10 +314,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 @@ -335,7 +342,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