Browse Source

Gracefully handle the conectionError when logging in

Jaime van Kessel 6 years ago
parent
commit
2a0954f246
1 changed files with 8 additions and 3 deletions
  1. 8 3
      cura/OAuth2/AuthorizationHelpers.py

+ 8 - 3
cura/OAuth2/AuthorizationHelpers.py

@@ -81,9 +81,14 @@ class AuthorizationHelpers:
     #   \param access_token: The encoded JWT token.
     #   \return: Dict containing some profile data.
     def parseJWT(self, access_token: str) -> Optional["UserProfile"]:
-        token_request = requests.get("{}/check-token".format(self._settings.OAUTH_SERVER_URL), headers = {
-            "Authorization": "Bearer {}".format(access_token)
-        })
+        try:
+            token_request = requests.get("{}/check-token".format(self._settings.OAUTH_SERVER_URL), headers = {
+                "Authorization": "Bearer {}".format(access_token)
+            })
+        except ConnectionError:
+            # Connection was suddenly dropped. Nothing we can do about that.
+            Logger.logException("e", "Something failed while attempting to parse the JWT token")
+            return None
         if token_request.status_code not in (200, 201):
             Logger.log("w", "Could not retrieve token data from auth server: %s", token_request.text)
             return None