From 12f59531469e23270fc27d83900bda7c372f21d2 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sat, 14 Mar 2026 21:58:00 +0000 Subject: [PATCH] fix(api): remove error exceptions in API responses Mainly a security thing, we don't want actual code errors being given in the API response, as someone could find out how the inner workings of the code behaves. --- server/app.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/app.py b/server/app.py index 95ba846..f373843 100644 --- a/server/app.py +++ b/server/app.py @@ -74,7 +74,7 @@ def register_user(): return jsonify({"error": str(e)}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 print(f"Registered new user: {username}") return jsonify({"message": f"User '{username}' registered successfully"}), 200 @@ -99,7 +99,7 @@ def login_user(): return jsonify({"error": "Invalid username or password"}), 401 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/profile", methods=["GET"]) @@ -245,9 +245,9 @@ def upload_data(): } ), 202 except ValueError as e: - return jsonify({"error": f"Failed to read JSONL file: {str(e)}"}), 400 + return jsonify({"error": f"Failed to read JSONL file"}), 400 except Exception as e: - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset/", methods=["GET"]) @jwt_required() @@ -350,10 +350,10 @@ def content_endpoint(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset//summary", methods=["GET"]) @@ -372,10 +372,10 @@ def get_summary(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset//time", methods=["GET"]) @@ -394,10 +394,10 @@ def get_time_analysis(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset//user", methods=["GET"]) @@ -416,10 +416,10 @@ def get_user_analysis(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset//cultural", methods=["GET"]) @@ -438,10 +438,10 @@ def get_cultural_analysis(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 @app.route("/dataset//interaction", methods=["GET"]) @@ -460,10 +460,10 @@ def get_interaction_analysis(dataset_id): except NonExistentDatasetException: return jsonify({"error": "Dataset does not exist"}), 404 except ValueError as e: - return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + return jsonify({"error": f"Malformed or missing data"}), 400 except Exception as e: print(traceback.format_exc()) - return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + return jsonify({"error": f"An unexpected error occurred"}), 500 if __name__ == "__main__":