From 3571e7b0708582896b5e41a6ed00ffb197a8c5d0 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Tue, 7 Dec 2021 15:37:09 +0300 Subject: [PATCH] Don't drop tokens if refresh failed due to a connection issue --- capi/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/capi/__init__.py b/capi/__init__.py index 281d65a..b39bece 100644 --- a/capi/__init__.py +++ b/capi/__init__.py @@ -1,3 +1,5 @@ +import requests + from . import model from . import utils from . import exceptions @@ -146,9 +148,15 @@ class CAPIAuthorizer: msg['description'] = 'Token were successfully updated' return msg + except requests.ConnectionError as e: + logger.warning(f'Connection problem on refresh for {state!r}', exc_info=e) + msg['status'] = 'error' + msg['description'] = 'Connection Error' + raise exceptions.RefreshFail(msg['description'], msg['status'], state) + except Exception as e: # probably here something don't work - logger.warning(f'Fail on refreshing token for {state}, row:{row}') + logger.warning(f'Fail on refreshing token for {state!r}, row:{row}', exc_info=e) msg['status'] = 'error' self.model.increment_refresh_tries(state)