From 2ab47b79684a835b129340f2cec5238f43b48648 Mon Sep 17 00:00:00 2001 From: ShahRustam Date: Mon, 4 May 2020 13:14:52 +0300 Subject: [PATCH] Remove account state item if refreshing token failed (#3487) --- platformio/commands/account/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platformio/commands/account/client.py b/platformio/commands/account/client.py index 5381dab9..c2bc3c5f 100644 --- a/platformio/commands/account/client.py +++ b/platformio/commands/account/client.py @@ -206,9 +206,12 @@ class AccountClient(object): self.api_base_url + "/v1/login", headers={"Authorization": "Bearer %s" % auth.get("refresh_token")}, ) - result = self.raise_error_from_response(response) - app.set_state_item("account", result) - return result.get("auth").get("access_token") + try: + result = self.raise_error_from_response(response) + app.set_state_item("account", result) + return result.get("auth").get("access_token") + except exception.AccountError: + app.delete_state_item("account") raise exception.AccountNotAuthenticated() @staticmethod