Improve ChunkedRetriever error handling and documentation
This commit is contained in:
@@ -126,11 +126,9 @@ class ContentLengthRetriever(Retriever):
|
|||||||
try:
|
try:
|
||||||
buffer = self.client.read(remaining)
|
buffer = self.client.read(remaining)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
logging.error("Timed out before receiving the complete payload")
|
|
||||||
raise IncompleteResponse("Timed out before receiving complete payload")
|
raise IncompleteResponse("Timed out before receiving complete payload")
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
logging.error("Connection closed before receiving the complete payload")
|
raise IncompleteResponse("Connection closed before receiving the complete payload")
|
||||||
raise IncompleteResponse("Connection closed before receiving complete payload")
|
|
||||||
|
|
||||||
if len(buffer) == 0:
|
if len(buffer) == 0:
|
||||||
logging.warning("Received payload length %s less than expected %s", cur_payload_size, self.length)
|
logging.warning("Received payload length %s less than expected %s", cur_payload_size, self.length)
|
||||||
@@ -164,7 +162,9 @@ class ChunkedRetriever(Retriever):
|
|||||||
Returns an iterator of the received message bytes.
|
Returns an iterator of the received message bytes.
|
||||||
The size of each iteration is not necessarily constant.
|
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 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.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
chunk_size = self.__get_chunk_size()
|
chunk_size = self.__get_chunk_size()
|
||||||
logging.debug("chunk-size: %s", chunk_size)
|
logging.debug("chunk-size: %s", chunk_size)
|
||||||
@@ -178,6 +178,11 @@ class ChunkedRetriever(Retriever):
|
|||||||
|
|
||||||
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):
|
def __get_chunk_size(self):
|
||||||
line = self.client.read_line()
|
line = self.client.read_line()
|
||||||
sep_pos = line.find(";")
|
sep_pos = line.find(";")
|
||||||
|
Reference in New Issue
Block a user