From 7abafb70e1f885794b6181d516c7c84afcf29a6c Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 9 Oct 2020 10:19:32 +0300 Subject: [PATCH] Fixed bad exception handling in version_update.py --- monkey/common/utils/exceptions.py | 4 ++++ monkey/monkey_island/cc/services/version_update.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/monkey/common/utils/exceptions.py b/monkey/common/utils/exceptions.py index fa026933c..5134ade0a 100644 --- a/monkey/common/utils/exceptions.py +++ b/monkey/common/utils/exceptions.py @@ -20,3 +20,7 @@ class CredentialsNotRequiredError(RegistrationNotNeededError): class AlreadyRegisteredError(RegistrationNotNeededError): """ Raise to indicate the reason why registration is not required """ + + +class NoInternetError(Exception): + """ Raise to indicate problems caused when no internet connection is present""" diff --git a/monkey/monkey_island/cc/services/version_update.py b/monkey/monkey_island/cc/services/version_update.py index ad1f81513..e4dea2b95 100644 --- a/monkey/monkey_island/cc/services/version_update.py +++ b/monkey/monkey_island/cc/services/version_update.py @@ -3,6 +3,7 @@ import logging import requests import monkey_island.cc.environment.environment_singleton as env_singleton +from common.utils.exceptions import NoInternetError from common.version import get_version __author__ = "itay.mizeretz" @@ -29,8 +30,8 @@ class VersionUpdateService: if VersionUpdateService.newer_version is None: try: VersionUpdateService.newer_version = VersionUpdateService._check_new_version() - except Exception: - logger.exception('Failed updating version number') + except NoInternetError: + logger.info('Failed updating version number') return VersionUpdateService.newer_version @@ -42,7 +43,11 @@ class VersionUpdateService: """ url = VersionUpdateService.VERSION_SERVER_CHECK_NEW_URL % (env_singleton.env.get_deployment(), get_version()) - reply = requests.get(url, timeout=15) + try: + reply = requests.get(url, timeout=7) + except requests.exceptions.RequestException: + logger.info("Can't get latest monkey version, probably no connection to the internet.") + raise NoInternetError res = reply.json().get('newer_version', None)