mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Handeling different types of response.data (#11576)
This commit is contained in:
parent
b4e9ff7ce0
commit
5bced09fc5
@ -214,8 +214,15 @@ class APIView(views.APIView):
|
||||
'user_name': request.user,
|
||||
'url_path': request.path,
|
||||
'remote_addr': request.META.get('REMOTE_ADDR', None),
|
||||
'error': response.data.get('error', response.status_text),
|
||||
}
|
||||
|
||||
if type(response.data) is dict:
|
||||
msg_data['error'] = response.data.get('error', response.status_text)
|
||||
elif type(response.data) is list:
|
||||
msg_data['error'] = ", ".join(list(map(lambda x: x.get('error', response.status_text), response.data)))
|
||||
else:
|
||||
msg_data['error'] = response.status_text
|
||||
|
||||
try:
|
||||
status_msg = getattr(settings, 'API_400_ERROR_LOG_FORMAT').format(**msg_data)
|
||||
except Exception as e:
|
||||
|
||||
@ -24,3 +24,8 @@ def test_custom_400_error_log(caplog, post, admin_user):
|
||||
with override_settings(API_400_ERROR_LOG_FORMAT="{status_code} {error}"):
|
||||
post(url=reverse('api:setting_logging_test'), data={}, user=admin_user, expect=409)
|
||||
assert '409 Logging not enabled' in caplog.text
|
||||
|
||||
|
||||
# The above tests the generation function with a dict/object.
|
||||
# The tower-qa test tests.api.inventories.test_inventory_update.TestInventoryUpdate.test_update_all_inventory_sources_with_nonfunctional_sources tests the function with a list
|
||||
# Someday it would be nice to test the else condition (not a dict/list) but we need to find an API test which will do this. For now it was added just as a catch all
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user