Skip to content
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

Add request getter/setter to HTTPError #2158

Merged
merged 2 commits into from Apr 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions httpx/_exceptions.py
Expand Up @@ -58,6 +58,17 @@ class HTTPError(Exception):

def __init__(self, message: str) -> None:
super().__init__(message)
self._request: typing.Optional["Request"] = None

@property
def request(self) -> "Request":
if self._request is None:
raise RuntimeError("The .request property has not been set.")
return self._request

@request.setter
def request(self, request: "Request") -> None:
self._request = request


class RequestError(HTTPError):
Expand All @@ -75,16 +86,6 @@ def __init__(self, message: str, *, request: "Request" = None) -> None:
# have a `.request` property set on them.
self._request = request

@property
def request(self) -> "Request":
if self._request is None:
raise RuntimeError("The .request property has not been set.")
return self._request

@request.setter
def request(self, request: "Request") -> None:
self._request = request


class TransportError(RequestError):
"""
Expand Down