Skip to content

Commit

Permalink
Refactor request exception wrapper (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkuzmik committed Sep 27, 2023
1 parent f4d3f3f commit af9817a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/comet_llm/experiment_api/request_exception_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ def wrapper(*args, **kwargs) -> Any: # type: ignore
f"installation is up-to-date and check the traceback for more details."
)

if (
exception.request is not None
and exception.response is not None
and 400 <= exception.response.status_code < 600
):
LOGGER.debug(f"Response:\n{pformat(vars(exception.response))}")
LOGGER.debug(f"Request:\n{pformat(vars(exception.request))}")
_debug_log(exception)

raise exceptions.CometLLMException(*exception_args) from exception

Expand All @@ -62,3 +56,11 @@ def _is_on_prem(url: str) -> bool:
parsed = urllib.parse.urlparse(url)
root = f"{parsed.scheme}://{parsed.hostname}/"
return root != "https://www.comet.com/"


def _debug_log(exception: requests.RequestException) -> None:
if exception.request is not None:
LOGGER.debug(f"Request:\n{pformat(vars(exception.request))}")

if exception.response is not None:
LOGGER.debug(f"Response:\n{pformat(vars(exception.response))}")

0 comments on commit af9817a

Please sign in to comment.