optimize something

pull/18952/head
xiongyao 1 year ago
parent 241125e487
commit 284d322a9f

@ -29,19 +29,25 @@ def create_flask_app_with_configs() -> DifyApp:
# log request data info # log request data info
request_id = get_request_id() request_id = get_request_id()
if "application/json" in request.headers.get("content-type", "").lower():
logging.info( try:
f"[before request]|request_id: {request_id}," if request.method.lower() == "post" and "application/json" in request.headers.get("content-type",
f" method: {request.method}, url: {request.url}, request_data: {request.get_json()}" "").lower():
) logging.info(
else: f"[before request]|request_id: {request_id},"
logging.info(f"[before request]|request_id: {request_id}, method: {request.method}, url: {request.url}") f" method: {request.method}, url: {request.url}, request_data: {request.get_json()}"
)
else:
logging.info(f"[before request]|request_id: {request_id}, method: {request.method}, url: {request.url}")
except Exception as e:
logging.info(f"before_request handler err {e}")
# add extra `request_id` field for every response data # add extra `request_id` field for every response data
@dify_app.after_request @dify_app.after_request
def add_extra_info(resp): def add_extra_info(resp):
obj = resp.get_json() obj = resp.get_json()
if isinstance(obj, dict): if obj is not None and isinstance(obj, dict):
request_id = get_request_id() request_id = get_request_id()
obj["request_id"] = request_id obj["request_id"] = request_id
resp.set_data(json.dumps(obj)) resp.set_data(json.dumps(obj))

Loading…
Cancel
Save