Skip to content

Commit

Permalink
Move deprecation error back to _handle_request().
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Nov 29, 2020
1 parent 0c2f949 commit ddd00f7
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ async def _handle_request(
resp = await self._request_handler(request)
finally:
self._current_request = None
except (HTTPException, asyncio.CancelledError):
except HTTPException as exc:
resp = exc
reset = await self.finish_response(request, resp, start_time)
except asyncio.CancelledError:
raise
except asyncio.TimeoutError as exc:
self.log_debug("Request handler timed out.", exc_info=exc)
Expand All @@ -432,6 +435,15 @@ async def _handle_request(
resp = self.handle_error(request, 500, exc)
reset = await self.finish_response(request, resp, start_time)
else:
# Deprecation warning (See #2415)
if getattr(resp, "__http_exception__", False):
warnings.warn(
"returning HTTPException object is deprecated "
"(#2415) and will be removed, "
"please raise the exception instead",
DeprecationWarning,
)

reset = await self.finish_response(request, resp, start_time)

return resp, reset
Expand Down Expand Up @@ -478,21 +490,9 @@ async def start(self) -> None:
task = self._loop.create_task(self._handle_request(request, start))
try:
resp, reset = await task
except HTTPException as exc:
resp = exc
reset = await self.finish_response(request, resp, start)
except (asyncio.CancelledError, ConnectionError):
self.log_debug("Ignored premature client disconnection")
break
else:
# Deprecation warning (See #2415)
if getattr(resp, "__http_exception__", False):
warnings.warn(
"returning HTTPException object is deprecated "
"(#2415) and will be removed, "
"please raise the exception instead",
DeprecationWarning,
)

# Drop the processed task from asyncio.Task.all_tasks() early
del task
Expand Down

0 comments on commit ddd00f7

Please sign in to comment.