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 LocalProtocolError, RemoteProtocolError #129

Merged
merged 5 commits into from
Aug 2, 2020

Conversation

tomchristie
Copy link
Member

Distinguish between local and remote protocol errors, so that we can expose local errors for invalid requests, eg...

>>> import httpcore
>>> http = httpcore.SyncConnectionPool()
>>> http.request(b"GET", (b'https', b'example.org', 443, b'/'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 153, in request
    method, url, headers=headers, stream=stream, timeout=timeout
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 93, in request
    return self.connection.request(method, url, headers, stream, timeout)
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/http11.py", line 61, in request
    self._send_request(method, url, headers, timeout)
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/http11.py", line 88, in _send_request
    event = h11.Request(method=method, target=target, headers=headers)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore._exceptions.LocalProtocolError: Missing mandatory Host: header

And...

>>> import httpcore
>>> http = httpcore.SyncConnectionPool()
>>> http.request(b"GET", (b'https', b'', 443, b'/'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 130, in request
    raise LocalProtocolError("Missing hostname in URL.")
httpcore._exceptions.LocalProtocolError: Missing hostname in URL.

@tomchristie tomchristie added the enhancement New feature or request label Aug 2, 2020
@tomchristie tomchristie added this to the 0.10.0 milestone Aug 2, 2020
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.

Sweet!

I have a question - do we even need ProtocolError anymore? I don't think it's being used elsewhere in the package anymore. Edit: okay, ProtocolError is kept as the base class, that makes sense and I hadn't seen that. :-)

@tomchristie tomchristie merged commit f4240b6 into master Aug 2, 2020
@tomchristie tomchristie deleted the local-and-remote-protocol-error branch August 2, 2020 11:59
@tomchristie tomchristie mentioned this pull request Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants