Skip to content

Commit 87ba05b

Browse files
GabLeRouxrokob
authored andcommitted
Adds failing test example for #223 502 bad gateway (#224)
* Adds failing test example for #223 * special case 502 errors
1 parent b4bcae4 commit 87ba05b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

rollbar/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,9 @@ def _parse_response(path, access_token, params, resp, endpoint=None):
13901390
if resp.status_code == 429:
13911391
log.warning("Rollbar: over rate limit, data was dropped. Payload was: %r", params)
13921392
return
1393+
elif resp.status_code == 502:
1394+
log.exception('Rollbar api returned a 502')
1395+
return
13931396
elif resp.status_code == 413:
13941397
uuid = None
13951398
host = None

rollbar/test/test_rollbar.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ def test_trigger_failsafe(self, post, _send_failsafe):
436436
rollbar.report_exc_info()
437437
self.assertEqual(_send_failsafe.call_count, 2)
438438

439+
@mock.patch('rollbar._send_failsafe')
440+
@mock.patch('rollbar.lib.transport.post',
441+
side_effect=lambda *args, **kw: MockRawResponse('<html>\r\n' \
442+
'<head><title>502 Bad Gateway</title></head>\r\n' \
443+
'<body bgcolor="white">\r\n' \
444+
'<center><h1>502 Bad Gateway</h1></center>\r\n' \
445+
'<hr><center>nginx</center>\r\n' \
446+
'</body>\r\n' \
447+
'</html>\r\n', 502))
448+
def test_502_failsafe(self, post, _send_failsafe):
449+
rollbar.report_message('derp')
450+
# self.assertEqual(_send_failsafe.call_count, 1)
451+
452+
try:
453+
raise Exception('trigger_failsafe')
454+
except:
455+
rollbar._post_api('/api/1/item', {'derp'})
456+
439457
@mock.patch('rollbar.send_payload')
440458
def test_send_failsafe(self, send_payload):
441459
test_uuid = str(uuid.uuid4())
@@ -1217,6 +1235,19 @@ def content(self):
12171235
def json(self):
12181236
return self.json_data
12191237

1238+
1239+
class MockRawResponse:
1240+
def __init__(self, data, status_code):
1241+
self.data = data
1242+
self.status_code = status_code
1243+
1244+
@property
1245+
def content(self):
1246+
return self.data
1247+
1248+
def json(self):
1249+
return self.data
1250+
12201251
class MockLambdaContext(object):
12211252
def __init__(self, x):
12221253
self.function_name = 1

0 commit comments

Comments
 (0)