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

Rename HTTPError to RequestError, introduce HTTPStatusError #869

Closed
wants to merge 2 commits into from

Conversation

sileht
Copy link

@sileht sileht commented Mar 21, 2020

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

@sileht sileht force-pushed the feat-http-status-error branch 4 times, most recently from 7247ce4 to e003e6b Compare March 21, 2020 14:10
@sileht
Copy link
Author

sileht commented Mar 21, 2020

I don't see any automated CI here, there is plan to add one ? Can I help ? I just see other pr have travis-ci

@florimondmanca
Copy link
Member

@sileht Seems like Travis is under scheduled maintenance right now:

We will be undergoing scheduled maintenance. During this time, your builds triggered via GitHub will still be accepted, but all public services (including api.travis-ci.org) cannot be reached. Any scheduled or running builds will be canceled and re-enqueued to begin running after the maintenance window.

It seems your build should start automatically once maintenance is over. :-)

Copy link
Member

@florimondmanca florimondmanca left a 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. :)

@florimondmanca
Copy link
Member

Going to try and trigger the Travis CI build...

@sileht
Copy link
Author

sileht commented Mar 23, 2020

Any places in the docs that need updating?

That's surprise me, but I didn't find any reference of HTTPError in the documentation.

Copy link
Member

@florimondmanca florimondmanca left a 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.

@florimondmanca florimondmanca requested a review from a team March 25, 2020 08:26
@florimondmanca florimondmanca changed the title feat: introduce HTTPStatusError Rename HTTPError to RequestError, introduce HTTPStatusError Mar 25, 2020
@florimondmanca florimondmanca added the user-experience Ensuring that users have a good experience using the library label Mar 25, 2020
@sileht sileht force-pushed the feat-http-status-error branch 2 times, most recently from 962c7e7 to becaa15 Compare March 28, 2020 14:23
@sileht
Copy link
Author

sileht commented Mar 28, 2020

I added a commit with some basic doc.

@florimondmanca
Copy link
Member

florimondmanca commented Mar 28, 2020

Thanks!

I added a commit with some basic doc.

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 Exceptions section in the Developer Interface, with info generated from exception docstrings...)

@sileht sileht force-pushed the feat-http-status-error branch from 609205f to 1de291b Compare March 28, 2020 15:11
@sileht
Copy link
Author

sileht commented Mar 28, 2020

I have split it.

sileht added 2 commits March 28, 2020 16:11
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
Copy link
Member

@florimondmanca florimondmanca left a 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 :-)

Copy link
Member

@florimondmanca florimondmanca left a 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.
"""

Copy link
Member

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".)

Suggested change
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.)

@florimondmanca
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving exception handling, HTTPError is misleading.
2 participants