99
1010from ldclient .interfaces import UpdateProcessor
1111from ldclient .sse_client import SSEClient
12- from ldclient .util import _stream_headers , log , UnsuccessfulResponseException
12+ from ldclient .util import _stream_headers , log , UnsuccessfulResponseException , http_error_message , is_http_error_recoverable
1313from ldclient .versioned_data_kind import FEATURES , SEGMENTS
1414
1515# allows for up to 5 minutes to elapse without any data sent across the stream. The heartbeats sent as comments on the
@@ -49,14 +49,11 @@ def run(self):
4949 log .info ("StreamingUpdateProcessor initialized ok." )
5050 self ._ready .set ()
5151 except UnsuccessfulResponseException as e :
52- log .error ("Received unexpected status code %d for stream connection" % e .status )
53- if e .status == 401 :
54- log .error ("Received 401 error, no further streaming connection will be made since SDK key is invalid" )
52+ log .error (http_error_message (e .status , "stream connection" ))
53+ if not is_http_error_recoverable (e .status ):
5554 self ._ready .set () # if client is initializing, make it stop waiting; has no effect if already inited
5655 self .stop ()
5756 break
58- else :
59- log .warning ("Restarting stream connection after one second." )
6057 except Exception as e :
6158 log .warning ("Caught exception. Restarting stream connection after one second. %s" % e )
6259 # no stacktrace here because, for a typical connection error, it'll just be a lengthy tour of urllib3 internals
@@ -66,7 +63,7 @@ def _backoff_expo():
6663 return backoff .expo (max_value = 30 )
6764
6865 def should_not_retry (e ):
69- return isinstance (e , UnsuccessfulResponseException ) and (e . response . status_code == 401 )
66+ return isinstance (e , UnsuccessfulResponseException ) and (not is_http_error_recoverable ( e . status ) )
7067
7168 @backoff .on_exception (_backoff_expo , BaseException , max_tries = None , jitter = backoff .full_jitter ,
7269 giveup = should_not_retry )
0 commit comments