From fb48a2181a51aa79987fcf792968c844597474a3 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 12 Feb 2022 13:31:09 +0100 Subject: [PATCH] improve errors --- backend/config.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/backend/config.py b/backend/config.py index 6d0a199..0d2340a 100644 --- a/backend/config.py +++ b/backend/config.py @@ -75,19 +75,29 @@ class ProxyElem: for url in urls: if isinstance(url, tuple): clean_urls.append(url[0]) - link_requests.append( - ProxyCreateLink.parse_obj( - {"upstream": url[0], "ctype": url[1], "region": self.region} - ) - ) else: clean_urls.append(url) - link_requests.append( - ProxyCreateLink.parse_obj({"upstream": url, "region": self.region}) - ) if not isinstance(proxy_server, str): return clean_urls + try: + for url in urls: + if isinstance(url, tuple): + link_requests.append( + ProxyCreateLink.parse_obj( + {"upstream": url[0], "ctype": url[1], "region": self.region} + ) + ) + else: + link_requests.append( + ProxyCreateLink.parse_obj( + {"upstream": url, "region": self.region} + ) + ) + except pydantic.ValidationError as e: + logger.info(e) + return clean_urls + response_data: ProxyRequest response_data: ProxyResponse @@ -105,7 +115,7 @@ class ProxyElem: response_data = cast( ProxyResponse, ProxyResponse.parse_obj(await resp.text()) ) - except Exception as e: + except (aiohttp.ClientError, pydantic.ValidationError) as e: logger.info(e) else: ret_data = []