diff options
author | Lipu Fei <lipu.fei815@gmail.com> | 2019-04-23 10:07:16 +0300 |
---|---|---|
committer | Lipu Fei <lipu.fei815@gmail.com> | 2019-04-23 10:07:19 +0300 |
commit | 97def2f6b111cf4c3ca9e85e2ddff236c072a242 (patch) | |
tree | 0b54de9024e483f661ed340ad24b8087d0455c86 /plugins/CuraDrive | |
parent | 50ad4e4d4e4908e4cda957f100a4bdadd5526603 (diff) |
Handle requests ConnectionErrors in Backup plugin
CURA-6471
Diffstat (limited to 'plugins/CuraDrive')
-rw-r--r-- | plugins/CuraDrive/src/DriveApiService.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/plugins/CuraDrive/src/DriveApiService.py b/plugins/CuraDrive/src/DriveApiService.py index 49e242d851..d8349ccc29 100644 --- a/plugins/CuraDrive/src/DriveApiService.py +++ b/plugins/CuraDrive/src/DriveApiService.py @@ -45,7 +45,7 @@ class DriveApiService: "Authorization": "Bearer {}".format(access_token) }) except requests.exceptions.ConnectionError: - Logger.log("w", "Unable to connect with the server.") + Logger.logException("w", "Unable to connect with the server.") return [] # HTTP status 300s mean redirection. 400s and 500s are errors. @@ -98,7 +98,12 @@ class DriveApiService: # If there is no download URL, we can't restore the backup. return self._emitRestoreError() - download_package = requests.get(download_url, stream = True) + try: + download_package = requests.get(download_url, stream = True) + except requests.exceptions.ConnectionError: + Logger.logException("e", "Unable to connect with the server") + return self._emitRestoreError() + if download_package.status_code >= 300: # Something went wrong when attempting to download the backup. Logger.log("w", "Could not download backup from url %s: %s", download_url, download_package.text) @@ -142,9 +147,14 @@ class DriveApiService: Logger.log("w", "Could not get access token.") return False - delete_backup = requests.delete("{}/{}".format(self.BACKUP_URL, backup_id), headers = { - "Authorization": "Bearer {}".format(access_token) - }) + try: + delete_backup = requests.delete("{}/{}".format(self.BACKUP_URL, backup_id), headers = { + "Authorization": "Bearer {}".format(access_token) + }) + except requests.exceptions.ConnectionError: + Logger.logException("e", "Unable to connect with the server") + return False + if delete_backup.status_code >= 300: Logger.log("w", "Could not delete backup: %s", delete_backup.text) return False @@ -159,15 +169,19 @@ class DriveApiService: if not access_token: Logger.log("w", "Could not get access token.") return None - - backup_upload_request = requests.put(self.BACKUP_URL, json = { - "data": { - "backup_size": backup_size, - "metadata": backup_metadata - } - }, headers = { - "Authorization": "Bearer {}".format(access_token) - }) + try: + backup_upload_request = requests.put( + self.BACKUP_URL, + json = {"data": {"backup_size": backup_size, + "metadata": backup_metadata + } + }, + headers = { + "Authorization": "Bearer {}".format(access_token) + }) + except requests.exceptions.ConnectionError: + Logger.logException("e", "Unable to connect with the server") + return None # Any status code of 300 or above indicates an error. if backup_upload_request.status_code >= 300: |