Browse Source

Merge pull request #5365 from Ultimaker/fix-token-expiry

Fix token expiry
Jaime van Kessel 6 years ago
parent
commit
7ed1ee4365
2 changed files with 8 additions and 2 deletions
  1. 1 1
      cura/OAuth2/AuthorizationService.py
  2. 7 1
      plugins/CuraDrive/src/DriveApiService.py

+ 1 - 1
cura/OAuth2/AuthorizationService.py

@@ -110,7 +110,7 @@ class AuthorizationService:
         # We have a fallback on a date far in the past for currently stored auth data in cura.cfg.
         received_at = datetime.strptime(self._auth_data.received_at, TOKEN_TIMESTAMP_FORMAT) \
             if self._auth_data.received_at else datetime(2000, 1, 1)
-        expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in or 0))
+        expiry_date = received_at + timedelta(seconds = float(self._auth_data.expires_in or 0) - 60)
         if datetime.now() > expiry_date:
             self.refreshAccessToken()
 

+ 7 - 1
plugins/CuraDrive/src/DriveApiService.py

@@ -54,7 +54,13 @@ class DriveApiService:
             Logger.log("w", "Could not get backups list from remote: %s", backup_list_request.text)
             Message(catalog.i18nc("@info:backup_status", "There was an error listing your backups."), title = catalog.i18nc("@info:title", "Backup")).show()
             return []
-        return backup_list_request.json()["data"]
+
+        backup_list_response = backup_list_request.json()
+        if "data" not in backup_list_response:
+            Logger.log("w", "Could not get backups from remote, actual response body was: %s", str(backup_list_response))
+            return []
+
+        return backup_list_response["data"]
 
     def createBackup(self) -> None:
         self.creatingStateChanged.emit(is_creating = True)