From 2508faca25c0f952a99aaf9cb316bb9966132bac Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Fri, 20 Sep 2024 14:06:05 +0100 Subject: [PATCH] Fix lost details on HttpProcessingError (#9052) (#9205) (cherry picked from commit 89114196040e6b4e435799939dfde6141223cc12) --- CHANGES/9052.bugfix.rst | 1 + aiohttp/client_proto.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 CHANGES/9052.bugfix.rst diff --git a/CHANGES/9052.bugfix.rst b/CHANGES/9052.bugfix.rst new file mode 100644 index 00000000000..913288d3368 --- /dev/null +++ b/CHANGES/9052.bugfix.rst @@ -0,0 +1 @@ +Fixed exception information getting lost on ``HttpProcessingError`` -- by :user:`Dreamsorcerer`. diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index e612450c746..9230ae5145b 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -266,7 +266,15 @@ def data_received(self, data: bytes) -> None: # closed in this case self.transport.close() # should_close is True after the call - self.set_exception(HttpProcessingError(), underlying_exc) + if isinstance(underlying_exc, HttpProcessingError): + exc = HttpProcessingError( + code=underlying_exc.code, + message=underlying_exc.message, + headers=underlying_exc.headers, + ) + else: + exc = HttpProcessingError() + self.set_exception(exc, underlying_exc) return self._upgraded = upgraded