Improve ChunkedRetriever error handling and documentation
This commit is contained in:
@@ -126,11 +126,9 @@ class ContentLengthRetriever(Retriever):
|
||||
try:
|
||||
buffer = self.client.read(remaining)
|
||||
except TimeoutError:
|
||||
logging.error("Timed out before receiving the complete payload")
|
||||
raise IncompleteResponse("Timed out before receiving complete payload")
|
||||
except ConnectionError:
|
||||
logging.error("Connection closed before receiving the complete payload")
|
||||
raise IncompleteResponse("Connection closed before receiving complete payload")
|
||||
raise IncompleteResponse("Connection closed before receiving the complete payload")
|
||||
|
||||
if len(buffer) == 0:
|
||||
logging.warning("Received payload length %s less than expected %s", cur_payload_size, self.length)
|
||||
@@ -164,19 +162,26 @@ class ChunkedRetriever(Retriever):
|
||||
Returns an iterator of the received message bytes.
|
||||
The size of each iteration is not necessarily constant.
|
||||
@raise IncompleteResponse: if the connection is closed or timed out before receiving the complete payload.
|
||||
@raise InvalidResponse: if the length of a chunk could not be determined.
|
||||
"""
|
||||
while True:
|
||||
chunk_size = self.__get_chunk_size()
|
||||
logging.debug("chunk-size: %s", chunk_size)
|
||||
if chunk_size == 0:
|
||||
# remove all trailing lines
|
||||
self.client.reset_request()
|
||||
break
|
||||
try:
|
||||
while True:
|
||||
chunk_size = self.__get_chunk_size()
|
||||
logging.debug("chunk-size: %s", chunk_size)
|
||||
if chunk_size == 0:
|
||||
# remove all trailing lines
|
||||
self.client.reset_request()
|
||||
break
|
||||
|
||||
buffer = self.client.read(chunk_size)
|
||||
yield buffer
|
||||
buffer = self.client.read(chunk_size)
|
||||
yield buffer
|
||||
|
||||
self.client.read_line() # remove trailing CRLF
|
||||
self.client.read_line() # remove trailing CRLF
|
||||
|
||||
except TimeoutError:
|
||||
raise IncompleteResponse("Timed out before receiving the complete payload!")
|
||||
except ConnectionError:
|
||||
raise IncompleteResponse("Connection closed before receiving the complete payload!")
|
||||
|
||||
def __get_chunk_size(self):
|
||||
line = self.client.read_line()
|
||||
|
Reference in New Issue
Block a user