Skip to content

Commit

Permalink
Merge pull request #87 from thiagofigueiro/samuelrohr-raise_exception…
Browse files Browse the repository at this point in the history
…_on_http_request_error

Samuelrohr raise exception on http request error
  • Loading branch information
thiagofigueiro authored Dec 12, 2019
2 parents 4a03892 + 7777c38 commit 260be06
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import find_packages, setup

package_name = 'nexus3-cli'
package_version = '2.1.2'
package_version = '2.1.3'

requires = [
'clint',
Expand Down
1 change: 1 addition & 0 deletions src/nexuscli/cli/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CliReturnCode(Enum):
SUCCESS = 0
NO_FILES = 1
API_ERROR = 2
CONNECTION_ERROR = 3
INVALID_SUBCOMMAND = 10
POLICY_NOT_FOUND = 20
REPOSITORY_NOT_FOUND = 30
Expand Down
8 changes: 7 additions & 1 deletion src/nexuscli/cli/subcommand_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,10 @@ def main(argv=None):
"""Entrypoint for ``nexus3 repository`` subcommand."""
arguments = docopt(__doc__, argv=argv)
command_method = util.find_cmd_method(arguments, globals())
return command_method(util.get_client(), arguments)

# TODO: generic implementation in src/nexuscli/cli/__init__.py
try:
return command_method(util.get_client(), arguments)
except exception.NexusClientConnectionError as e:
print(f'Connection error: {e}')
return errors.CliReturnCode.CONNECTION_ERROR.value
5 changes: 5 additions & 0 deletions src/nexuscli/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ class NexusClientAPIError(Exception):
pass


class NexusClientConnectionError(Exception):
"""Generic network connector error."""
pass


class NexusClientInvalidCredentials(Exception):
"""
Login credentials not accepted by Nexus service. Usually the result of a
Expand Down
3 changes: 1 addition & 2 deletions src/nexuscli/nexus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def http_request(self, method, endpoint, service_url=None, **kwargs):
method=method, auth=self.config.auth, url=url,
verify=self.config.x509_verify, **kwargs)
except requests.exceptions.ConnectionError as e:
print(e)
sys.exit(1)
raise exception.NexusClientConnectionError(str(e)) from None

if response.status_code == 401:
raise exception.NexusClientInvalidCredentials(
Expand Down

0 comments on commit 260be06

Please sign in to comment.