diff --git a/fedn/network/api/interface.py b/fedn/network/api/interface.py index 5cd465085..7fb6ae8ca 100644 --- a/fedn/network/api/interface.py +++ b/fedn/network/api/interface.py @@ -659,7 +659,7 @@ def set_initial_model(self, file): self.control.commit(file.filename, model) except Exception as e: logger.debug(e) - return jsonify({"success": False, "message": e}) + return jsonify({"success": False, "message": "Failed to add initial model."}) return jsonify({"success": True, "message": "Initial model added successfully."}) diff --git a/fedn/network/api/server.py b/fedn/network/api/server.py index 8f046ee80..e13cfdf5a 100644 --- a/fedn/network/api/server.py +++ b/fedn/network/api/server.py @@ -5,9 +5,8 @@ from fedn.common.config import get_controller_config from fedn.network.api.auth import jwt_auth_required from fedn.network.api.interface import API +from fedn.network.api.shared import control, statestore from fedn.network.api.v1 import _routes -from fedn.network.api.shared import statestore, control - custom_url_prefix = os.environ.get("FEDN_CUSTOM_URL_PREFIX", False) api = API(statestore, control) @@ -569,8 +568,10 @@ def add_combiner(): remote_addr = request.remote_addr try: response = api.add_combiner(**json_data, remote_addr=remote_addr) - except TypeError as e: - return jsonify({"success": False, "message": str(e)}), 400 + except TypeError: + return jsonify({"success": False, "message": "Invalid data provided"}), 400 + except Exception: + return jsonify({"success": False, "message": "An unexpected error occurred"}), 500 return response @@ -589,8 +590,10 @@ def add_client(): remote_addr = request.remote_addr try: response = api.add_client(**json_data, remote_addr=remote_addr) - except TypeError as e: - return jsonify({"success": False, "message": str(e)}), 400 + except TypeError: + return jsonify({"success": False, "message": "Invalid data provided"}), 400 + except Exception: + return jsonify({"success": False, "message": "An unexpected error occurred"}), 500 return response @@ -612,8 +615,10 @@ def list_combiners_data(): try: response = api.list_combiners_data(combiners) - except TypeError as e: - return jsonify({"success": False, "message": str(e)}), 400 + except TypeError: + return jsonify({"success": False, "message": "Invalid data provided"}), 400 + except Exception: + return jsonify({"success": False, "message": "An unexpected error occurred"}), 500 return response @@ -630,8 +635,10 @@ def get_plot_data(): try: feature = request.args.get("feature", None) response = api.get_plot_data(feature=feature) - except TypeError as e: - return jsonify({"success": False, "message": str(e)}), 400 + except TypeError: + return jsonify({"success": False, "message": "Invalid data provided"}), 400 + except Exception: + return jsonify({"success": False, "message": "An unexpected error occurred"}), 500 return response