aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks/discovery.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 20:03:49 +0100
committerDennis Fink2026-11-13 20:03:49 +0100
commit87117345ed6e99e5a070d919ac17139cba7b8fe4 (patch)
treed7df5d45008dd2959194e2614b87333598b85198 /webmentions_ssg/tasks/discovery.py
parent2fbe1d383650cb31f3ef8d58c04e4d4095935833 (diff)
downloadwebmentions-ssg-87117345ed6e99e5a070d919ac17139cba7b8fe4.tar.gz
webmentions-ssg-87117345ed6e99e5a070d919ac17139cba7b8fe4.zip
fix(core): make network task failures explicit
Introduce a dedicated response-size error so callers only translate expected limit violations instead of masking unrelated `ValueError` exceptions. Ensure failed sockets are always closed, remove dead discovery error handling, and log unexpected sender failures with tracebacks before recording them.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/tasks/discovery.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/webmentions_ssg/tasks/discovery.py b/webmentions_ssg/tasks/discovery.py
index 29c3e81..456e47e 100644
--- a/webmentions_ssg/tasks/discovery.py
+++ b/webmentions_ssg/tasks/discovery.py
@@ -11,7 +11,12 @@ import httpx
from bs4 import BeautifulSoup
from flask import current_app
-from ..net import is_http_url, is_temporary_status, read_limited_body
+from ..net import (
+ ResponseTooLargeError,
+ is_http_url,
+ is_temporary_status,
+ read_limited_body,
+)
LINK_SPLIT = re.compile(r",\s*(?=<)")
DISCOVERY_HEADERS = {"Accept": "text/html, application/xhtml+xml;q=0.9"}
@@ -130,7 +135,7 @@ def read_target_body(response: httpx.Response) -> bytes:
return read_limited_body(
response, current_app.config["MAX_TARGET_BYTES"], label="Target"
)
- except ValueError as exc:
+ except ResponseTooLargeError as exc:
raise PermanentSenderError(str(exc)) from exc
@@ -149,7 +154,7 @@ def discover_webmention_endpoint(client: httpx.Client, target: str) -> str | Non
"""
try:
head_response = client.head(target, headers=DISCOVERY_HEADERS)
- except httpx.RequestError, TemporarySenderError:
+ except httpx.RequestError:
# HEAD is only an optimization. Servers and intermediaries may reject
# or drop it even when fetching the document with GET would succeed.
pass