From 3a5a2ae8bc30974a9c2e427781f73c5bb7289835 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sat, 31 Jan 2026 20:20:08 +0000 Subject: [PATCH] refactor: improve error handling --- server/app.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/app.py b/server/app.py index 3ac27b9..15dc625 100644 --- a/server/app.py +++ b/server/app.py @@ -110,21 +110,22 @@ def filter_time(): try: start = pd.to_datetime(data["start"], utc=True) end = pd.to_datetime(data["end"], utc=True) + filtered_df = stat_obj.set_time_range(start, end) + return jsonify(filtered_df), 200 except Exception: return jsonify({"error": "Invalid datetime format"}), 400 - - filtered_df = stat_obj.set_time_range(start, end) - - return jsonify(filtered_df), 200 @app.route('/filter/reset', methods=["GET"]) def reset_dataset(): if stat_obj is None: return jsonify({"error": "No data uploaded"}), 400 - stat_obj.reset_dataset() - - return jsonify({"success": "Dataset successfully reset"}) + try: + stat_obj.reset_dataset() + return jsonify({"success": "Dataset successfully reset"}) + except Exception as e: + print(traceback.format_exc()) + return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 if __name__ == "__main__":