Skip to content

Commit b213740

Browse files
author
Borislav Dugosija
committed
Merge branch 'feature/retry-fix' into 'develop'
Feature/retry fix See merge request core/sevenbridges-python!114
2 parents 10fe4aa + abb71df commit b213740

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

sevenbridges/http/error_handlers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def maintenance_sleeper(api, response, sleep=300):
4343
:param sleep: Time to sleep in between the requests.
4444
"""
4545
while response.status_code == 503:
46+
content_type = response.headers.get('Content-Type')
47+
if content_type is None or 'application/json' not in content_type:
48+
return response
4649
logger.info(
4750
'Service unavailable: Response=[%s]',
4851
response.__dict__

tests/test_error_handlers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_rate_limit_sleeper(api):
3737
def test_maintenance_sleeper_invalid_json(api):
3838
resp503 = requests.Response()
3939
resp503.status_code = 503
40+
resp503.headers = {'Content-Type': 'application/json'}
4041

4142
api._session = MockSession([resp503])
4243
with pytest.raises(JSONDecodeError):
@@ -46,6 +47,7 @@ def test_maintenance_sleeper_invalid_json(api):
4647
def test_maintenance_sleeper(api):
4748
resp503 = requests.Response()
4849
resp503.status_code = 503
50+
resp503.headers = {'Content-Type': 'application/json'}
4951
resp503._content = b'{"code": 0}'
5052
resp200 = requests.Response()
5153
resp200.status_code = 200

0 commit comments

Comments
 (0)