aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoletdjnz <coletdjnz@protonmail.com>2024-09-08 19:32:44 +1200
committerGitHub <noreply@github.com>2024-09-08 19:32:44 +1200
commitd1c4d88b2d912e8da5e76db455562ca63b1af690 (patch)
tree3bf88e52bed9a78f64956e4df342fdbc334bdbb2
parent46f4c80bc363ee8116c33d37f65202e6c3470954 (diff)
[networking] Fix handler not being added to RequestError (#10955)
Authored by: coletdjnz
-rw-r--r--test/test_networking.py18
-rw-r--r--yt_dlp/networking/_helper.py4
2 files changed, 20 insertions, 2 deletions
diff --git a/test/test_networking.py b/test/test_networking.py
index 826f11a56..d96624af1 100644
--- a/test/test_networking.py
+++ b/test/test_networking.py
@@ -822,6 +822,24 @@ class TestRequestHandlerMisc:
rh.close()
assert len(logging_handlers) == before_count
+ def test_wrap_request_errors(self):
+ class TestRequestHandler(RequestHandler):
+ def _validate(self, request):
+ if request.headers.get('x-fail'):
+ raise UnsupportedRequest('test error')
+
+ def _send(self, request: Request):
+ raise RequestError('test error')
+
+ with TestRequestHandler(logger=FakeLogger()) as rh:
+ with pytest.raises(UnsupportedRequest, match='test error') as exc_info:
+ rh.validate(Request('http://example.com', headers={'x-fail': '1'}))
+ assert exc_info.value.handler is rh
+
+ with pytest.raises(RequestError, match='test error') as exc_info:
+ rh.send(Request('http://example.com'))
+ assert exc_info.value.handler is rh
+
@pytest.mark.parametrize('handler', ['Urllib'], indirect=True)
class TestUrllibRequestHandler(TestRequestHandlerBase):
diff --git a/yt_dlp/networking/_helper.py b/yt_dlp/networking/_helper.py
index fe3354ea2..b86d3606d 100644
--- a/yt_dlp/networking/_helper.py
+++ b/yt_dlp/networking/_helper.py
@@ -10,7 +10,7 @@ import typing
import urllib.parse
import urllib.request
-from .exceptions import RequestError, UnsupportedRequest
+from .exceptions import RequestError
from ..dependencies import certifi
from ..socks import ProxyType, sockssocket
from ..utils import format_field, traverse_obj
@@ -206,7 +206,7 @@ def wrap_request_errors(func):
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
- except UnsupportedRequest as e:
+ except RequestError as e:
if e.handler is None:
e.handler = self
raise