change: do not capture exception for loading har file

This commit is contained in:
debugtalk
2020-06-07 13:17:47 +08:00
parent d5fea81ea6
commit d1291d0f36

View File

@@ -6,7 +6,6 @@ from urllib.parse import unquote
import yaml import yaml
from loguru import logger from loguru import logger
from sentry_sdk import capture_exception
def load_har_log_entries(file_path): def load_har_log_entries(file_path):
@@ -32,10 +31,14 @@ def load_har_log_entries(file_path):
with io.open(file_path, "r+", encoding="utf-8-sig") as f: with io.open(file_path, "r+", encoding="utf-8-sig") as f:
try: try:
content_json = json.loads(f.read()) content_json = json.loads(f.read())
except (TypeError, JSONDecodeError) as ex:
logger.error(f"failed to load HAR file {file_path}: {ex}")
sys.exit(1)
try:
return content_json["log"]["entries"] return content_json["log"]["entries"]
except (KeyError, TypeError, JSONDecodeError) as ex: except KeyError:
capture_exception(ex) logger.error(f"log entries not found in HAR file: {content_json}")
logger.error("HAR file content error: {}".format(file_path))
sys.exit(1) sys.exit(1)
@@ -53,7 +56,7 @@ def x_www_form_urlencoded(post_data):
""" """
if isinstance(post_data, dict): if isinstance(post_data, dict):
return "&".join( return "&".join(
[u"{}={}".format(key, value) for key, value in post_data.items()] ["{}={}".format(key, value) for key, value in post_data.items()]
) )
else: else:
return post_data return post_data