From 7170c44b6c7398105f61ea13d5d1e46c579d4001 Mon Sep 17 00:00:00 2001 From: xinghengwang Date: Tue, 3 Jan 2017 17:38:06 -0800 Subject: [PATCH] not tested the case, but added body for in case the JSON can't be parsed. --- moesifdjango/middleware.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/moesifdjango/middleware.py b/moesifdjango/middleware.py index b623dbf..55b5e15 100644 --- a/moesifdjango/middleware.py +++ b/moesifdjango/middleware.py @@ -84,7 +84,15 @@ def flatten_to_string(value): req_body = json.loads(raw_request_body) req_body = mask_body(req_body, middleware_settings.get('REQUEST_BODY_MASKS')) except: - req_body = {"message": "can not serialize request body=" + str(raw_request_body)} + req_body = { + "moesif_error": { + "code": "json_parse_error", + "src": "moesifdjango", + "msg": ["Body is not a JSON Object or JSON Array"], + "args": [str(raw_request_body)], + } + } + #"code": "can not serialize request body=" + str(raw_request_body) ip_address = get_client_ip(request) uri = request.scheme + "://" + request.get_host() + request.get_full_path() @@ -102,8 +110,15 @@ def mapper(key): rsp_body = APIHelper.json_deserialize(response.content) rsp_body = mask_body(rsp_body, middleware_settings.get('RESPONSE_BODY_MASKS')) except: - rsp_body = {"message": "can not serialize response body=" + str(response.content)} - + rsp_body = { + "moesif_error": { + "code": "json_parse_error", + "src": "moesifdjango", + "msg": ["Body is not a JSON Object or JSON Array"], + "args": [str(response.content)], + } + } + #rsp_body = {"message": "can not serialize response body=" + str(response.content)} rsp_time = timezone.now()