def raise_error_from_response(response, expected_codes=(200, 201, 202)): if response.status_code in expected_codes: try: return response.json() except ValueError: pass try: message = response.json()["message"] except (KeyError, ValueError): message = response.text if "Authorization session has been expired" in message: app.delete_state_item("account") raise exception.AccountError(message)
def logout(self): try: refresh_token = self.get_refresh_token() except: # pylint:disable=bare-except raise exception.AccountNotAuthenticated() response = requests.post( self.api_base_url + "/v1/logout", data={"refresh_token": refresh_token}, ) try: self.raise_error_from_response(response) except exception.AccountError: pass app.delete_state_item("account") return True
def delete_local_session(): app.delete_state_item("account")