diff --git a/githubkit/exception.py b/githubkit/exception.py index b1ee2d48c..fa36ffd98 100644 --- a/githubkit/exception.py +++ b/githubkit/exception.py @@ -46,7 +46,7 @@ def __init__(self, response: "Response"): def __repr__(self) -> str: return ( f"{self.__class__.__name__}(method={self.request.method}, " - f"url={self.request.url}, status_code={self.response.status_code})" + f"url={self.request.url}, status_code={self.response._status_reason})" ) @@ -60,7 +60,7 @@ def __init__(self, response: "Response", retry_after: timedelta): def __repr__(self) -> str: return ( f"{self.__class__.__name__}(method={self.request.method}, " - f"url={self.request.url}, status_code={self.response.status_code}, " + f"url={self.request.url}, status_code={self.response._status_reason}, " f"retry_after={self.retry_after})" ) diff --git a/githubkit/response.py b/githubkit/response.py index 881f2c2c6..ae5c01825 100644 --- a/githubkit/response.py +++ b/githubkit/response.py @@ -13,7 +13,7 @@ def __init__(self, response: httpx.Response, data_model: Type[RT]): self._data_model = data_model def __repr__(self) -> str: - return f"Response({self.status_code}, data_model={self._data_model})" + return f"Response({self._status_reason}, data_model={self._data_model})" @property def raw_request(self) -> httpx.Request: @@ -27,6 +27,18 @@ def raw_response(self) -> httpx.Response: def status_code(self) -> int: return self._response.status_code + @property + def reason_phrase(self) -> str: + return self._response.reason_phrase + + @property + def _status_reason(self) -> str: + return ( + f"{self.status_code} {reason}" + if (reason := self.reason_phrase) + else str(self.status_code) + ) + @property def headers(self) -> httpx.Headers: return self._response.headers