(
self,
hook_ctx: HookContext,
request: httpx.Request,
is_error_status_code: Callable[[int], bool],
stream: bool = False,
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
)
| 310 | return http_res |
| 311 | |
| 312 | async def do_request_async( |
| 313 | self, |
| 314 | hook_ctx: HookContext, |
| 315 | request: httpx.Request, |
| 316 | is_error_status_code: Callable[[int], bool], |
| 317 | stream: bool = False, |
| 318 | retry_config: Optional[Tuple[RetryConfig, List[str]]] = None, |
| 319 | ) -> httpx.Response: |
| 320 | client = self.sdk_configuration.async_client |
| 321 | logger = self.sdk_configuration.debug_logger |
| 322 | |
| 323 | hooks = self.sdk_configuration.__dict__["_hooks"] |
| 324 | |
| 325 | async def do(): |
| 326 | http_res = None |
| 327 | try: |
| 328 | req = await run_sync_in_thread( |
| 329 | hooks.before_request, BeforeRequestContext(hook_ctx), request |
| 330 | ) |
| 331 | |
| 332 | if "timeout" in request.extensions and "timeout" not in req.extensions: |
| 333 | req.extensions["timeout"] = request.extensions["timeout"] |
| 334 | logger.debug( |
| 335 | "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s", |
| 336 | req.method, |
| 337 | req.url, |
| 338 | req.headers, |
| 339 | get_body_content(req), |
| 340 | ) |
| 341 | |
| 342 | if client is None: |
| 343 | raise ValueError("client is required") |
| 344 | |
| 345 | http_res = await client.send(req, stream=stream) |
| 346 | except Exception as e: |
| 347 | _, e = await run_sync_in_thread( |
| 348 | hooks.after_error, AfterErrorContext(hook_ctx), None, e |
| 349 | ) |
| 350 | |
| 351 | if e is not None: |
| 352 | logger.debug("Request Exception", exc_info=True) |
| 353 | raise e |
| 354 | |
| 355 | if http_res is None: |
| 356 | logger.debug("Raising no response SDK error") |
| 357 | raise errors.NoResponseError("No response received") |
| 358 | |
| 359 | logger.debug( |
| 360 | "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s", |
| 361 | http_res.status_code, |
| 362 | http_res.url, |
| 363 | http_res.headers, |
| 364 | "<streaming response>" if stream else http_res.text, |
| 365 | ) |
| 366 | |
| 367 | return http_res |
| 368 | |
| 369 | if retry_config is not None: |
no test coverage detected