diff options
Diffstat (limited to 'webmentions_ssg/tasks')
| -rw-r--r-- | webmentions_ssg/tasks/sender.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py index 4da1a5c..9330247 100644 --- a/webmentions_ssg/tasks/sender.py +++ b/webmentions_ssg/tasks/sender.py @@ -422,6 +422,9 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: response_status: int | None = None try: + if not is_http_url(target): + raise PermanentSenderError(f"Invalid target URL: {target!r}") + with httpx.Client( headers={"User-Agent": (f"{APP_NAME}/{VERSION} SentWebmention")}, timeout=httpx.Timeout(current_app.config.get("REQUEST_TIMEOUT", 5.0)), @@ -460,6 +463,31 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: raise PermanentSenderError(message) + except ( + PermanentSenderError, + UnsafeAddressError, + httpx.InvalidURL, + httpx.UnsupportedProtocol, + httpx.LocalProtocolError, + ValueError, + UnicodeError, + ) as exc: + # Malformed URLs and local request/protocol errors cannot be repaired + # by retrying this source revision. InvalidURL is not a RequestError; + # protocol errors are, so handle them before the retryable branch. + if not attempt_is_current(webmention, revision): + return + + webmention.processed_revision = revision + webmention.next_retry_at = None + webmention.status = SentWebmentionStatus.FAILED + webmention.failure_reason = str(exc) or type(exc).__name__ + webmention.endpoint = endpoint + webmention.response_status = response_status + + db.session.commit() + return + except (TemporarySenderError, AddressResolutionError, httpx.RequestError) as exc: if not attempt_is_current(webmention, revision): return @@ -483,20 +511,6 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: # No Huey retries: only the scanner may requeue after next_retry_at. return - except (PermanentSenderError, UnsafeAddressError) as exc: - if not attempt_is_current(webmention, revision): - return - - webmention.processed_revision = revision - webmention.next_retry_at = None - webmention.status = SentWebmentionStatus.FAILED - webmention.failure_reason = str(exc) - webmention.endpoint = endpoint - webmention.response_status = response_status - - db.session.commit() - return - if not attempt_is_current(webmention, revision): return |
