| 124 | ) # ty: ignore[invalid-assignment] |
| 125 | |
| 126 | async def app(scope: Scope, receive: Receive, send: Send) -> None: |
| 127 | request = Request(scope, receive, send) |
| 128 | |
| 129 | async def app(scope: Scope, receive: Receive, send: Send) -> None: |
| 130 | # Starts customization |
| 131 | response_awaited = False |
| 132 | async with AsyncExitStack() as request_stack: |
| 133 | scope["fastapi_inner_astack"] = request_stack |
| 134 | async with AsyncExitStack() as function_stack: |
| 135 | scope["fastapi_function_astack"] = function_stack |
| 136 | response = await f(request) |
| 137 | await response(scope, receive, send) |
| 138 | # Continues customization |
| 139 | response_awaited = True |
| 140 | if not response_awaited: |
| 141 | raise FastAPIError( |
| 142 | "Response not awaited. There's a high chance that the " |
| 143 | "application code is raising an exception and a dependency with yield " |
| 144 | "has a block with a bare except, or a block with except Exception, " |
| 145 | "and is not raising the exception again. Read more about it in the " |
| 146 | "docs: https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#dependencies-with-yield-and-except" |
| 147 | ) |
| 148 | |
| 149 | # Same as in Starlette |
| 150 | await wrap_app_handling_exceptions(app, request)(scope, receive, send) |
| 151 | |
| 152 | return app |
| 153 | |