From 7ba775628276e8aa1ee8ad48a5139a19a07da5ff Mon Sep 17 00:00:00 2001 From: barrierye Date: Thu, 7 Mar 2024 12:05:22 +0800 Subject: [PATCH] =?UTF-8?q?AgentRuntime=E4=BC=98=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appbuilder/core/agent.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/appbuilder/core/agent.py b/appbuilder/core/agent.py index 0999451de..c0f7fb288 100644 --- a/appbuilder/core/agent.py +++ b/appbuilder/core/agent.py @@ -228,9 +228,12 @@ def create_flask_app(self, url_rule="/chat"): def handle_bad_request(e): return {"code": 400, "message": f'{e}', "result": None}, 400 - @app.errorhandler(RuntimeError) + @app.errorhandler(Exception) def handle_bad_request(e): - return {"code": 1000, "message": f'{e}', "result": None}, 200 + if hasattr(e, "code"): + return {"code": e.code, "message": str(e), "result": None}, 200 + else: + return {"code": 500, "message": "Internal Server Error", "result": None}, 200 def warp(): # 根据component是否lazy_certification,分成两种情况: @@ -305,7 +308,8 @@ def gen_sse_resp(stream_message): }, ensure_ascii=False) + "\n\n" self.user_session._post_append() except Exception as e: - err_resp = {"code": 1000, "message": str(e), "result": None} + code = 500 if not hasattr(e, "code") else e.code + err_resp = {"code": code, "message": str(e), "result": None} logging.error(f"[request_id={request_id}, session_id={session_id}] err={e}", exc_info=True) yield "data: " + json.dumps(err_resp, ensure_ascii=False) + "\n\n" return Response( @@ -322,7 +326,7 @@ def gen_sse_resp(stream_message): } except Exception as e: logging.error(f"[request_id={request_id}, session_id={session_id}] err={e}", exc_info=True) - raise RuntimeError(e) + raise e app.add_url_rule(url_rule, 'chat', warp, methods=['POST']) return app