Skip to content

Feature: add reason phrase to response and exceptions #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 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
Loading