Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 7893fd2

Browse files
committed
Switch out RuntimeError
1 parent 6975483 commit 7893fd2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

hyper/common/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ class ChunkedDecodeError(Exception):
1010
An error was encountered while decoding a chunked response.
1111
"""
1212
pass
13+
14+
15+
class InvalidResponseError(Exception):
16+
"""
17+
A problem was found with the response that makes it invalid.
18+
"""
19+
pass

hyper/http11/response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import zlib
1111

1212
from ..common.decoder import DeflateDecoder
13-
from ..common.exceptions import ChunkedDecodeError
13+
from ..common.exceptions import ChunkedDecodeError, InvalidResponseError
1414
from ..http20.exceptions import ConnectionResetError
1515

1616
log = logging.getLogger(__name__)
@@ -96,7 +96,6 @@ def read(self, amt=None, decode_content=True):
9696
if self._chunked:
9797
return self._normal_read_chunked(amt, decode_content)
9898

99-
10099
# If we're asked to do a read without a length, we need to read
101100
# everything. That means either the entire content length, or until the
102101
# socket is closed, depending.
@@ -106,7 +105,9 @@ def read(self, amt=None, decode_content=True):
106105
elif self._expect_close:
107106
return self._read_expect_closed(decode_content)
108107
else: # pragma: no cover
109-
raise RuntimeError("Unbounded read!")
108+
raise InvalidResponseError(
109+
"Response must either have length or Connection: close"
110+
)
110111

111112
# Otherwise, we've been asked to do a bounded read. We should read no
112113
# more than the remaining length, obviously.

0 commit comments

Comments
 (0)