Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AgentRuntime优化错误码 #168

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions appbuilder/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,分成两种情况:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
Loading