A context manager that can be used to attach the given request context to any `RequestError` exceptions that are raised within the block.
(
request: Request | None = None,
)
| 365 | |
| 366 | @contextlib.contextmanager |
| 367 | def request_context( |
| 368 | request: Request | None = None, |
| 369 | ) -> typing.Iterator[None]: |
| 370 | """ |
| 371 | A context manager that can be used to attach the given request context |
| 372 | to any `RequestError` exceptions that are raised within the block. |
| 373 | """ |
| 374 | try: |
| 375 | yield |
| 376 | except RequestError as exc: |
| 377 | if request is not None: |
| 378 | exc.request = request |
| 379 | raise exc |
no outgoing calls
no test coverage detected