-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
Rename HTTPError
to RequestError
, introduce HTTPStatusError
#869
Conversation
7247ce4
to
e003e6b
Compare
|
@sileht Seems like Travis is under scheduled maintenance right now:
It seems your build should start automatically once maintenance is over. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is looking great to me already.
Any places in the docs that need updating?
Also going to ask a review from @tomchristie on this API change. :)
Going to try and trigger the Travis CI build... |
That's surprise me, but I didn't find any reference of HTTPError in the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. :-) I also think this is definitely an improvement over the ambiguity of HTTPError
as the base exception class in HTTPX.
Waiting for some more feedback before merging…
Possible follow-up work might be adding documenting exception classes that are exposed on httpx.[...]
to the docs, since I believe we've been considering them as public API for a while.
HTTPError
to RequestError
, introduce HTTPStatusError
962c7e7
to
becaa15
Compare
I added a commit with some basic doc. |
Thanks!
Ideally, can we move this to a separate PR? In general we try to have one PR do one thing, but this one PR already does two things… :-) This doc addition is small, but I've got a bunch of copy nits, and it'd be better not to mix with this feature PR (which is ready to be merged without the docs addition). (I'm also wondering if exceptions docs wouldn't be better served by adding an |
609205f
to
1de291b
Compare
I have split it. |
Unlike HTTPStatusError, HTTPError name is not always related to HTTP status code >= 400. The base class is renamed RequestError, to avoid confusion with HTTPStatusError. Related encode#867
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick suggestion about something I hadn't clicked about before :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another improvement suggestion… Sorry for submitting this in pieces!
""" | ||
HTTP Status Error. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since HTTPStatusError
will in practice always both have a .request
and a .response
attached, we should probably ensure this by overriding the constructor?
This will help type checkers understand that these attributes aren't Optional
in this case. (Otherwise, accessing eg exc.response.status_code
would raise a type checking error like Item "None" of "Optional[Response]" has no attribute "status_code"
.)
def __init__(self, *args: typing.Any, response: "Response") -> None: | |
super().__init__(*args) | |
self.request: "Request" = response.request | |
self.response: "Response" = response |
(The type comments are important to override the annotations from the base class.)
I'm going to close this for now — there's been some changes and improvements since March in the realm of the exception hierarchy, and I think we might need to properly discuss and agree on the changes proposed here beforehand. Filed #1064. Either way, @sileht thank you so much for putting time into this. This is definitely super valuable and I'm sure we'll be able to reuse this very soon! |
feat: introduce HTTPStatusError
Fixes #867
feat: rename HTTPError to RequestError
Unlike HTTPStatusError, HTTPError name is not always related to HTTP status code >= 400.
The base class is renamed RequestError, to avoid confusion with
HTTPStatusError.
Related #867