Skip to content

Commit

Permalink
#184: Avoid catching bare exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 3, 2020
1 parent 51fabee commit 9b85ea7
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions datagateway_api/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,61 @@ class Config(object):
def __init__(self):
config_path = Path(__file__).parent.parent.parent / "config.json"
with open(config_path) as target:

self.config = json.load(target)
target.close()

def get_backend_type(self):
try:
return self.config["backend"]
except:
except KeyError:
sys.exit("Missing config value, backend")

def get_db_url(self):
try:
return self.config["DB_URL"]
except:
except KeyError:
sys.exit("Missing config value, DB_URL")

def get_icat_url(self):
try:
return self.config["ICAT_URL"]
except:
except KeyError:
sys.exit("Missing config value, ICAT_URL")

def get_icat_check_cert(self):
try:
return self.config["icat_check_cert"]
except:
# This could be set to true if there's no value, and log a warning
# that no value has been found from the config - save app from
# exiting
except KeyError:
sys.exit("Missing config value, icat_check_cert")

def get_log_level(self):
try:
return self.config["log_level"]
except:
except KeyError:
sys.exit("Missing config value, log_level")

def is_debug_mode(self):
try:
return self.config["debug_mode"]
except:
except KeyError:
sys.exit("Missing config value, debug_mode")

def is_generate_swagger(self):
try:
return self.config["generate_swagger"]
except:
except KeyError:
sys.exit("Missing config value, generate_swagger")

def get_host(self):
try:
return self.config["host"]
except:
except KeyError:
sys.exit("Missing config value, host")

def get_port(self):
try:
return self.config["port"]
except:
except KeyError:
sys.exit("Missing config value, port")

def get_icat_properties(self):
Expand Down

0 comments on commit 9b85ea7

Please sign in to comment.