fix: try json loads request_body only if it is not None

This commit is contained in:
debugtalk
2020-06-04 15:30:34 +08:00
parent 75228d15f0
commit 785610f735
+3 -2
View File
@@ -43,7 +43,9 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData:
# record actual request info # record actual request info
request_headers = dict(resp_obj.request.headers) request_headers = dict(resp_obj.request.headers)
request_cookies = resp_obj.request._cookies.get_dict() request_cookies = resp_obj.request._cookies.get_dict()
request_body = resp_obj.request.body request_body = resp_obj.request.body
if request_body is not None:
try: try:
request_body = json.loads(request_body) request_body = json.loads(request_body)
except json.JSONDecodeError as ex: except json.JSONDecodeError as ex:
@@ -53,10 +55,9 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData:
# bytes/bytearray: request body in protobuf # bytes/bytearray: request body in protobuf
capture_exception(ex) capture_exception(ex)
except TypeError as ex: except TypeError as ex:
# neither str nor bytes/bytearray, e.g. None # neither str nor bytes/bytearray
capture_exception(ex) capture_exception(ex)
if request_body:
request_content_type = lower_dict_keys(request_headers).get("content-type") request_content_type = lower_dict_keys(request_headers).get("content-type")
if request_content_type and "multipart/form-data" in request_content_type: if request_content_type and "multipart/form-data" in request_content_type:
# upload file type # upload file type