From 4d119b0f81550131255237abf1bdebb8f240b639 Mon Sep 17 00:00:00 2001 From: Dominic Ghizzoni Date: Wed, 2 Oct 2024 23:26:15 -0400 Subject: [PATCH] I modified app.py to make changes mentioned in issue #561 --- backend/analytics_server/app.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/analytics_server/app.py b/backend/analytics_server/app.py index c246a9c8..0fafc32b 100644 --- a/backend/analytics_server/app.py +++ b/backend/analytics_server/app.py @@ -1,6 +1,7 @@ from os import getenv -from flask import Flask +from flask import Flask, jsonify +from werkzeug.exceptions import HTTPException from env import load_app_env @@ -36,5 +37,19 @@ configure_db_with_app(app) initialize_database(app) +def handle_exception(e): + if isinstance(e, HTTPException): + return jsonify({ + "error": e.name, + "description": e.description, + "status_code": e.code + }), e.code + + return jsonify({ + "error": "Internal Server Error", + "description": str(e), + "status_code": 500 + }), 500 + if __name__ == "__main__": app.run(port=ANALYTICS_SERVER_PORT)