Handeling different types of response.data (#11576)

This commit is contained in:
John Westcott IV
2022-01-21 15:16:09 -05:00
committed by GitHub
parent b4e9ff7ce0
commit 5bced09fc5
2 changed files with 13 additions and 1 deletions

View File

@@ -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: