Apply some defensive programming

We have logs that retrieving the `accessToken` would crash Cura. By adding some defensive programming, in combination with proper error logging the crash no longer happens, and as programmers we have proper logging where the error occurred.

CURA-11640
This commit is contained in:
c.lamboo 2024-03-12 09:24:55 +01:00
parent 7c00d2f0b3
commit 6f0d2c1f0a
2 changed files with 6 additions and 2 deletions

View File

@ -275,7 +275,11 @@ class Account(QObject):
@pyqtProperty(str, notify=accessTokenChanged)
def accessToken(self) -> Optional[str]:
return self._authorization_service.getAccessToken()
try:
return self._authorization_service.getAccessToken()
except Exception as e:
Logger.error("Failed to get access token: %s", str(e))
return None
@pyqtProperty("QVariantMap", notify = userProfileChanged)
def userProfile(self) -> Dict[str, Optional[str]]:

View File

@ -21,7 +21,7 @@ class UltimakerCloudScope(DefaultUserAgentScope):
def __init__(self, application: "CuraApplication"):
super().__init__(application)
api = application.getCuraAPI()
self._account = api.account # type: Account
self._account: Account = api.account
def requestHook(self, request: QNetworkRequest):
super().requestHook(request)