RFC error messages
frdel committed
Nov 18, 2024 at 21:41 UTC
bad39516462c44afd0dc3d05d0dac16359d28c54
3 files changed
+30
-8
python/helpers/rfc.py
+9
-1
@@ -74,7 +74,15 @@ async def _send_json_data(url: str, data: str):
74
url,
75
json=data,
76
) as response:
77
- return await response.json()
77
+ if response.status == 200:
78
+ result = await response.json()
79
+ if result["ok"]:
80
+ return result["result"]
81
+ else:
82
+ raise Exception(result["message"])
83
+ else:
84
+ error = await response.text()
85
+ raise Exception(error)
86
87
88
def hash_data(data: str, password: str):
python/helpers/runtime.py
+1
-1
@@ -70,7 +70,7 @@ def _get_rfc_url() -> str:
70
url = settings.get_settings()["rfc_url"]
71
if not url.endswith("/"):
72
url += "/"
73
- url += "url"
73
+ url += "rfc"
74
return url
75
# if get_arg("rfc_url"):
76
# return str(get_arg("rfc_url"))
run_ui.py
+20
-6
@@ -530,7 +530,7 @@ async def transcribe():
530
"message": str(e),
531
}
532
PrintStyle.error(str(e))
533
-
533
+
534
# respond with json
535
return jsonify(response)
536
@@ -539,12 +539,26 @@ async def transcribe():
539
@app.route("/rfc", methods=["POST"])
540
@requires_auth
541
async def handle_rfc():
542
- # data sent to the server
543
- input = json.loads(request.get_json())
542
+ try:
543
+ # data sent to the server
544
+ input = json.loads(request.get_json())
545
+
546
+ # handle RFC
547
+ result = await runtime.handle_rfc(input)
548
545
- # handle RFC
546
- result = await runtime.handle_rfc(input)
547
- return jsonify(result)
549
+ response = {
550
+ "ok": True,
551
+ "result": result,
552
+ }
553
+
554
+ return jsonify(response)
555
+ except Exception as e:
556
+ response = {
557
+ "ok": False,
558
+ "message": str(e),
559
+ }
560
+ PrintStyle.error(str(e))
561
+ return jsonify(response), 500
562
563
564
def run():