From bad39516462c44afd0dc3d05d0dac16359d28c54 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:41:39 +0100 Subject: [PATCH] RFC error messages --- python/helpers/rfc.py | 10 +++++++++- python/helpers/runtime.py | 2 +- run_ui.py | 26 ++++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/python/helpers/rfc.py b/python/helpers/rfc.py index dd5cbb720..aeee03dee 100644 --- a/python/helpers/rfc.py +++ b/python/helpers/rfc.py @@ -74,7 +74,15 @@ async def _send_json_data(url: str, data: str): url, json=data, ) as response: - return await response.json() + if response.status == 200: + result = await response.json() + if result["ok"]: + return result["result"] + else: + raise Exception(result["message"]) + else: + error = await response.text() + raise Exception(error) def hash_data(data: str, password: str): diff --git a/python/helpers/runtime.py b/python/helpers/runtime.py index e9b9d7de5..e60f2b18f 100644 --- a/python/helpers/runtime.py +++ b/python/helpers/runtime.py @@ -70,7 +70,7 @@ def _get_rfc_url() -> str: url = settings.get_settings()["rfc_url"] if not url.endswith("/"): url += "/" - url += "url" + url += "rfc" return url # if get_arg("rfc_url"): # return str(get_arg("rfc_url")) diff --git a/run_ui.py b/run_ui.py index 9e87d2746..fd65ae964 100644 --- a/run_ui.py +++ b/run_ui.py @@ -530,7 +530,7 @@ async def transcribe(): "message": str(e), } PrintStyle.error(str(e)) - + # respond with json return jsonify(response) @@ -539,12 +539,26 @@ async def transcribe(): @app.route("/rfc", methods=["POST"]) @requires_auth async def handle_rfc(): - # data sent to the server - input = json.loads(request.get_json()) + try: + # data sent to the server + input = json.loads(request.get_json()) - # handle RFC - result = await runtime.handle_rfc(input) - return jsonify(result) + # handle RFC + result = await runtime.handle_rfc(input) + + response = { + "ok": True, + "result": result, + } + + return jsonify(response) + except Exception as e: + response = { + "ok": False, + "message": str(e), + } + PrintStyle.error(str(e)) + return jsonify(response), 500 def run():