From 13e220ed111f0515b42d703d5aa7d4dffd95b5ab Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:36:54 +0200 Subject: [PATCH 1/7] decoding error --- ffun/ffun/feeds/entities.py | 1 + ffun/ffun/loader/domain.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ffun/ffun/feeds/entities.py b/ffun/ffun/feeds/entities.py index 5978121a..dec2fb39 100644 --- a/ffun/ffun/feeds/entities.py +++ b/ffun/ffun/feeds/entities.py @@ -32,6 +32,7 @@ class FeedError(enum.IntEnum): network_ssl_connection_error = 1014 network_all_connection_attempts_failed = 1015 network_received_unkomplete_body = 1016 + network_decoding_error = 1017 parsing_unknown = 2000 parsing_base_error = 2001 diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index 191f1c28..e8cf7a51 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -3,8 +3,6 @@ import anyio import httpx -from furl import furl - from ffun.core import logging, utils from ffun.feeds import domain as f_domain from ffun.feeds.entities import Feed, FeedError, FeedState @@ -16,6 +14,8 @@ from ffun.loader.settings import Proxy, settings from ffun.parsers import entities as p_entities from ffun.parsers.domain import parse_feed +from furl import furl + logger = logging.get_module_logger() @@ -138,6 +138,11 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R raise errors.LoadError(feed_error_code=error_code) from e + except httpx.DecodingError as e: + log.warning("network_decoding_error") + error_code = FeedError.network_decoding_error + raise errors.LoadError(feed_error_code=error_code) from e + except Exception as e: log.exception("error_while_loading_feed") raise errors.LoadError(feed_error_code=error_code) from e From 15917289735cf0ae17fa3f91026293d7fb76656a Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:40:29 +0200 Subject: [PATCH 2/7] proxy connection 403 --- ffun/ffun/feeds/entities.py | 1 + ffun/ffun/loader/domain.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/ffun/ffun/feeds/entities.py b/ffun/ffun/feeds/entities.py index dec2fb39..77000e11 100644 --- a/ffun/ffun/feeds/entities.py +++ b/ffun/ffun/feeds/entities.py @@ -45,6 +45,7 @@ class FeedError(enum.IntEnum): proxy_could_not_resolve_host = 4001 proxy_connection_refused = 4002 + proxy_connection_403 = 4003 class Feed(BaseEntity): diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index e8cf7a51..d7e7cb86 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -133,6 +133,9 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R elif "TUN_ERR" in message and "ECONNREFUSED" in message: log.warning("network_connection_refused") error_code = FeedError.proxy_connection_refused + elif '403' in message: + log.warning("403 Forbidden") + error_code = FeedError.proxy_connection_403 else: log.exception("unknown_proxy_error_while_loading_feed") From 9d5af01b88cea6c506854eeabcebdb9c38816233 Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:49:37 +0200 Subject: [PATCH 3/7] read error --- ffun/ffun/loader/domain.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index d7e7cb86..8da24bcd 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -63,6 +63,11 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R raise errors.LoadError(feed_error_code=error_code) from e + except httpx.ReadError as e: + error_code = FeedError.network_read_error + log.warning("network_read_error") + raise errors.LoadError(feed_error_code=error_code) from e + except httpx.ConnectError as e: message = str(e) From 35dc59073662ed1a5ebc631e284e9c34606bd99d Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:52:06 +0200 Subject: [PATCH 4/7] more errors processed --- ffun/ffun/loader/domain.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index 8da24bcd..5e86ba2e 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -64,8 +64,14 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R raise errors.LoadError(feed_error_code=error_code) from e except httpx.ReadError as e: - error_code = FeedError.network_read_error - log.warning("network_read_error") + message = str(e) + + if message == "": + error_code = FeedError.network_read_error + log.warning("network_read_error") + else: + log.exception("unknown_read_error_while_loading_feed") + raise errors.LoadError(feed_error_code=error_code) from e except httpx.ConnectError as e: @@ -74,6 +80,9 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R if "[Errno -2]" in message: log.warning("network_name_or_service_not_known") error_code = FeedError.network_name_or_service_not_known + elif "[Errno -3]" in message: + log.warning("network_temporary_failure_in_name_resolution") + error_code = FeedError.network_temporary_failure_in_name_resolution elif "[Errno -5]" in message: log.warning("no_address_associated_with_hostname") error_code = FeedError.network_no_address_associated_with_hostname From a393fdd1a8a76da896810cc13a5fdd1cd42a2aa4 Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:55:44 +0200 Subject: [PATCH 5/7] more errors processed --- ffun/ffun/loader/domain.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index 5e86ba2e..7e5d0c8e 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -142,13 +142,16 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R message = str(e) if message.startswith("502 Could not resolve host"): - log.warning("network_could_not_resolve_host") + log.warning("proxy_could_not_resolve_host") error_code = FeedError.proxy_could_not_resolve_host elif "TUN_ERR" in message and "ECONNREFUSED" in message: - log.warning("network_connection_refused") + log.warning("proxy_connection_refused") error_code = FeedError.proxy_connection_refused + elif "TUN_ERR" in message and "EHOSTUNREACH" in message: + log.warning("proxy_no_route_to_host") + error_code = FeedError.proxy_no_route_to_host elif '403' in message: - log.warning("403 Forbidden") + log.warning("proxy_connection_403") error_code = FeedError.proxy_connection_403 else: log.exception("unknown_proxy_error_while_loading_feed") From 501cc32f45cd0e855885084a1984aa4bba9551e2 Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:55:57 +0200 Subject: [PATCH 6/7] more error codes --- ffun/ffun/feeds/entities.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ffun/ffun/feeds/entities.py b/ffun/ffun/feeds/entities.py index 77000e11..38d66353 100644 --- a/ffun/ffun/feeds/entities.py +++ b/ffun/ffun/feeds/entities.py @@ -33,6 +33,8 @@ class FeedError(enum.IntEnum): network_all_connection_attempts_failed = 1015 network_received_unkomplete_body = 1016 network_decoding_error = 1017 + network_read_error = 1018 + network_temporary_failure_in_name_resolution = 1019 parsing_unknown = 2000 parsing_base_error = 2001 @@ -46,6 +48,7 @@ class FeedError(enum.IntEnum): proxy_could_not_resolve_host = 4001 proxy_connection_refused = 4002 proxy_connection_403 = 4003 + proxy_no_route_to_host = 4004 class Feed(BaseEntity): From 857650f489020124bd54e55fbacf172c1cc28cf8 Mon Sep 17 00:00:00 2001 From: "Aliaksei Yaletski (Tiendil)" Date: Tue, 14 May 2024 21:56:48 +0200 Subject: [PATCH 7/7] code formatting --- ffun/ffun/loader/domain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ffun/ffun/loader/domain.py b/ffun/ffun/loader/domain.py index 7e5d0c8e..1f9b7f39 100644 --- a/ffun/ffun/loader/domain.py +++ b/ffun/ffun/loader/domain.py @@ -3,6 +3,8 @@ import anyio import httpx +from furl import furl + from ffun.core import logging, utils from ffun.feeds import domain as f_domain from ffun.feeds.entities import Feed, FeedError, FeedState @@ -14,8 +16,6 @@ from ffun.loader.settings import Proxy, settings from ffun.parsers import entities as p_entities from ffun.parsers.domain import parse_feed -from furl import furl - logger = logging.get_module_logger() @@ -150,7 +150,7 @@ async def load_content( # noqa: CFQ001, CCR001, C901 # pylint: disable=R0912, R elif "TUN_ERR" in message and "EHOSTUNREACH" in message: log.warning("proxy_no_route_to_host") error_code = FeedError.proxy_no_route_to_host - elif '403' in message: + elif "403" in message: log.warning("proxy_connection_403") error_code = FeedError.proxy_connection_403 else: