Skip to content

Commit

Permalink
not tested the case, but added body for in case the JSON can't be par…
Browse files Browse the repository at this point in the history
…sed.
  • Loading branch information
xinghengwang committed Jan 4, 2017
1 parent 20a95f4 commit 7170c44
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions moesifdjango/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit 7170c44

Please sign in to comment.