From 95dea4e3a38645c878fa9d936263b1cd68becbc2 Mon Sep 17 00:00:00 2001 From: Maksym Naboka Date: Wed, 18 Jan 2017 17:47:37 -0800 Subject: [PATCH] http: raise exception if expired token (#880) - add raise DCOSAuthenticationException in dcos.http.request if token is invalid. - raise DCOSAuthenticationException or DCOSAuthorizationException in dcos.packagemanager.PackageManager().has_capability if user is not logged in --- dcos/http.py | 2 +- dcos/packagemanager.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dcos/http.py b/dcos/http.py index 672c01a..4b960b0 100644 --- a/dcos/http.py +++ b/dcos/http.py @@ -159,7 +159,7 @@ def request(method, if auth_token is not None: msg = ("Your core.dcos_acs_token is invalid. " "Please run: `dcos auth login`") - raise DCOSException(msg) + raise DCOSAuthenticationException(msg) else: raise DCOSAuthenticationException(response) elif response.status_code == 422: diff --git a/dcos/packagemanager.py b/dcos/packagemanager.py index 70a65fa..ac40187 100644 --- a/dcos/packagemanager.py +++ b/dcos/packagemanager.py @@ -67,6 +67,10 @@ class PackageManager: try: response = self.cosmos.call_endpoint( 'capabilities').json() + except DCOSAuthenticationException: + raise + except DCOSAuthorizationException: + raise except Exception as e: logger.exception(e) return False