From e596e3037e6a2fdff2f6c5cb862872d7d83f7db0 Mon Sep 17 00:00:00 2001 From: Joy Lal Chattaraj <8450903+chattarajoy@users.noreply.github.com> Date: Fri, 28 Feb 2020 10:02:15 +0530 Subject: [PATCH] handle all errors --- qds_sdk/connection.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/qds_sdk/connection.py b/qds_sdk/connection.py index c456a4e1..1274b7c1 100644 --- a/qds_sdk/connection.py +++ b/qds_sdk/connection.py @@ -22,9 +22,9 @@ """ -class MyAdapter(HTTPAdapter): +class RequestAdapter(HTTPAdapter): def __init__(self, *args, **kwargs): - super(MyAdapter, self).__init__(*args, **kwargs) + super(RequestAdapter, self).__init__(*args, **kwargs) def init_poolmanager(self, connections, maxsize,block=False): self.poolmanager = PoolManager(num_pools=connections, @@ -49,11 +49,11 @@ def __init__(self, auth, rest_url, skip_ssl_cert_check, self.base_retry_delay = base_retry_delay if reuse: self.session = requests.Session() - self.session.mount('https://', MyAdapter()) + self.session.mount('https://', RequestAdapter()) # retries for get requests self.session_with_retries = requests.Session() - self.session_with_retries.mount('https://', MyAdapter(max_retries=3)) + self.session_with_retries.mount('https://', RequestAdapter(max_retries=3)) def retry(ExceptionToCheck, tries=5, delay=10, backoff=2): def deco_retry(f): @@ -78,7 +78,7 @@ def f_retry(self, *args, **kwargs): return f_retry # true decorator return deco_retry - @retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry)) + @retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry, Error)) def get_raw(self, path, params=None): return self._api_call_raw("GET", path, params=params) @@ -107,7 +107,7 @@ def _api_call_raw(self, req_type, path, data=None, params=None): else: x = requests x_with_retries = requests.Session() - x_with_retries.mount('https://', MyAdapter(max_retries=3)) + x_with_retries.mount('https://', RequestAdapter(max_retries=3)) kwargs = {'headers': self._headers, 'auth': self.auth, 'verify': not self.skip_ssl_cert_check} @@ -131,12 +131,12 @@ def _api_call_raw(self, req_type, path, data=None, params=None): else: raise NotImplemented - self._validate_json(r) self._handle_error(r) return r def _api_call(self, req_type, path, data=None, params=None): response = self._api_call_raw(req_type, path, data=data, params=params) + self._validate_json(r) return response.json() @staticmethod