Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: add custom cloudflare errors + new overrides (#558)

NTFSvolumefc3c2ecbb02e
diff --git a/cyberdrop_dl/clients/errors.py b/cyberdrop_dl/clients/errors.py
index 566bce8c9..ba3965918 100644
--- a/cyberdrop_dl/clients/errors.py
+++ b/cyberdrop_dl/clients/errors.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import contextlib
from functools import singledispatch
from http import HTTPStatus
from pathlib import Path
@@ -17,6 +16,18 @@ if TYPE_CHECKING:
from cyberdrop_dl.scraper.crawler import ScrapeItem
from cyberdrop_dl.utils.data_enums_classes.url_objects import MediaItem
+# See: https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/
+CLOUDFLARE_ERRORS = {
+ 520: "Unexpected Response",
+ 521: "Web Server Down",
+ 522: "Connection Timeout",
+ 523: "Origin Is Unreachable",
+ 524: "Response Timeout",
+ 525: "SSL Handshake Failed",
+ 526: "Untrusted",
+ 530: "IP Banned / Restricted",
+}
+
class CDLBaseError(Exception):
"""Base exception for cyberdrop-dl errors."""
@@ -160,9 +171,13 @@ class InvalidYamlError(CDLBaseError):
@singledispatch
def create_error_msg(error: int) -> str:
- with contextlib.suppress(ValueError):
+ try:
msg = HTTPStatus(error).phrase
return f"{error} {msg}"
+ except ValueError:
+ cloudflare_error = CLOUDFLARE_ERRORS.get(error)
+ if cloudflare_error:
+ return f"{error} {cloudflare_error}"
return f"{error} HTTP Error"
diff --git a/cyberdrop_dl/ui/progress/statistic_progress.py b/cyberdrop_dl/ui/progress/statistic_progress.py
index 9266e8ac0..336f6bb8f 100644
--- a/cyberdrop_dl/ui/progress/statistic_progress.py
+++ b/cyberdrop_dl/ui/progress/statistic_progress.py
@@ -12,7 +12,22 @@ FAILURE_OVERRIDES = {
"ClientConnectorCertificateError": "Client Connector Certificate Error",
"ClientConnectorDNSError": "Client Connector DNS Error",
"ClientConnectorError": "Client Connector Error",
- "ConnectionTimeoutError": "Connection Timeout Error",
+ "ClientConnectorSSLError": "Client Connector SSL Error",
+ "ClientHttpProxyError": "Client HTTP Proxy Error",
+ "ClientPayloadError": "Client Payload Error",
+ "ClientProxyConnectionError": "Client Proxy Connection Error",
+ "ConnectionTimeoutError": "Connection Timeout",
+ "ContentTypeError": "Content Type Error",
+ "InvalidURL": "Invalid URL",
+ "InvalidUrlClientError": "Invalid URL Client Error",
+ "InvalidUrlRedirectClientError": "Invalid URL Redirect",
+ "NonHttpUrlRedirectClientError": "Non HTTP URL Redirect",
+ "RedirectClientError": "Redirect Error",
+ "ServerConnectionError": "Server Connection Error",
+ "ServerDisconnectedError": "Server Disconnected",
+ "ServerFingerprintMismatch": "Server Fingerprint Mismatch",
+ "ServerTimeoutError": "Server Timeout Error",
+ "SocketTimeoutError": "Socket Timeout Error",
}