From 25715f5aee3fb0a3d8b9cf79c872e2502d30cc7c Mon Sep 17 00:00:00 2001 From: forest Date: Tue, 5 Oct 2021 10:50:31 -0500 Subject: [PATCH] dont silently crash when database connection fails --- capsulflask/db.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/capsulflask/db.py b/capsulflask/db.py index 8dac950..f216fc6 100644 --- a/capsulflask/db.py +++ b/capsulflask/db.py @@ -12,11 +12,18 @@ from capsulflask.shared import my_exec_info_message def init_app(app, is_running_server): - app.config['PSYCOPG2_CONNECTION_POOL'] = psycopg2.pool.SimpleConnectionPool( - 1, - 20, - app.config['POSTGRES_CONNECTION_PARAMETERS'] - ) + try: + app.config['PSYCOPG2_CONNECTION_POOL'] = psycopg2.pool.SimpleConnectionPool( + 1, + 20, + app.config['POSTGRES_CONNECTION_PARAMETERS'] + ) + except: + app.logger.error(f""" + error was thrown when connecting to postgres database: + {my_exec_info_message(sys.exc_info())}""" + ) + raise # tell the app to clean up the DB connection when shutting down. app.teardown_appcontext(close_db)