Skip to content

Commit

Permalink
✨ improve error info
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored May 21, 2024
1 parent 9221b59 commit a7f561b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions githubkit/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
)


Expand All @@ -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})"
)

Expand Down
14 changes: 13 additions & 1 deletion githubkit/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Check warning on line 32 in githubkit/response.py

View check run for this annotation

Codecov / codecov/patch

githubkit/response.py#L32

Added line #L32 was not covered by tests

@property
def _status_reason(self) -> str:
return (

Check warning on line 36 in githubkit/response.py

View check run for this annotation

Codecov / codecov/patch

githubkit/response.py#L36

Added line #L36 was not covered by tests
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
Expand Down

0 comments on commit a7f561b

Please sign in to comment.