From 57b41c2ec3f68db1c81212e82f0b69fd006891c0 Mon Sep 17 00:00:00 2001 From: harshpatel4_crest Date: Tue, 1 Jun 2021 14:23:01 +0530 Subject: [PATCH] Modified some error messages --- tap_github/__init__.py | 17 ++++++++++++----- tests/unittests/test_verify_access.py | 10 +++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tap_github/__init__.py b/tap_github/__init__.py index 130fea69..483ad960 100644 --- a/tap_github/__init__.py +++ b/tap_github/__init__.py @@ -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) @@ -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): @@ -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) diff --git a/tests/unittests/test_verify_access.py b/tests/unittests/test_verify_access.py index 92191512..59fb7e7e 100644 --- a/tests/unittests/test_verify_access.py +++ b/tests/unittests/test_verify_access.py @@ -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.") @@ -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)) @@ -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))