File tree 2 files changed +14
-3
lines changed 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,14 @@ class InfluxDBError(Exception):
12
12
13
13
def __init__ (self , response : HTTPResponse ):
14
14
"""Initialize the InfluxDBError handler."""
15
- self .response = response
16
- self .message = self ._get_message (response )
17
- self .retry_after = response .getheader ('Retry-After' )
15
+ if response is not None :
16
+ self .response = response
17
+ self .message = self ._get_message (response )
18
+ self .retry_after = response .getheader ('Retry-After' )
19
+ else :
20
+ self .response = None
21
+ self .message = 'no response'
22
+ self .retry_after = None
18
23
super ().__init__ (self .message )
19
24
20
25
def _get_message (self , response ):
Original file line number Diff line number Diff line change @@ -46,3 +46,9 @@ def test_message_get_retry_after(self):
46
46
influx_db_error = InfluxDBError (response = HTTPResponse (reason = "too many requests" ))
47
47
self .assertEqual ("too many requests" , str (influx_db_error ))
48
48
self .assertEqual (None , influx_db_error .retry_after )
49
+
50
+ def test_no_response (self ):
51
+ influx_db_error = InfluxDBError (response = None )
52
+ self .assertEqual ("no response" , str (influx_db_error ))
53
+ self .assertIsNone (influx_db_error .response )
54
+ self .assertIsNone (influx_db_error .retry_after )
You can’t perform that action at this time.
0 commit comments