diff options
Diffstat (limited to 'resumejson_converter/utils/json.py')
-rw-r--r-- | resumejson_converter/utils/json.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/resumejson_converter/utils/json.py b/resumejson_converter/utils/json.py index 77e1312..fb44899 100644 --- a/resumejson_converter/utils/json.py +++ b/resumejson_converter/utils/json.py @@ -1,4 +1,3 @@ -import sys import logging import json @@ -34,17 +33,25 @@ def load(json_filepath): """ try: logging.info("JSON parsing...") - with open(json_filepath, 'r') as f: - resume_json = json.load(f) + if type(json_filepath) is str: + with open(json_filepath, 'r') as f: + resume_json = json.load(f) + elif type(json_filepath) is dict: + resume_json = json_filepath + else: + msg = "{} is not a valid type, type accepted are <class 'str'>\n\ + or <class 'dict'>.".format(type(json_filepath)) + logging.error(msg) + raise TypeError except IOError: msg = "Json file could not be loaded. Perhaps file path: \n\ [{}] is incorrect".format(json_filepath) - logging.exception(msg) - sys.exit(1) + logging.error(msg) + raise except ValueError: - logging.exception( + logging.error( "Json file could not be loaded. The syntax is not valid.") - sys.exit(1) + raise else: resume = Resume(resume_json) try: @@ -52,8 +59,8 @@ def load(json_filepath): except InvalidResumeError: msg = "The json resume don't respect standard. Check: \n\ https://jsonresume.org/schema/." - logging.exception(msg) - sys.exit(1) + logging.error(msg) + raise else: logging.info("JSON parsing done.") return JsonObject(resume_json) |