From 04af80cb4ca0dc15cc4ccb1550f6497cf52518f1 Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Fri, 21 Jun 2024 17:21:03 +0800 Subject: [PATCH] feat: add trace_config_check_error --- api/controllers/console/app/error.py | 6 ++++++ api/controllers/console/app/ops_trace.py | 6 ++++-- api/services/ops_trace/ops_trace_service.py | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/controllers/console/app/error.py b/api/controllers/console/app/error.py index cd7919b5e426bd..f6feed12217a85 100644 --- a/api/controllers/console/app/error.py +++ b/api/controllers/console/app/error.py @@ -109,3 +109,9 @@ class TracingConfigIsExist(BaseHTTPException): error_code = 'trace_config_is_exist' description = "Trace config is exist." code = 400 + + +class TracingConfigCheckError(BaseHTTPException): + error_code = 'trace_config_check_error' + description = "Invalid Credentials." + code = 400 diff --git a/api/controllers/console/app/ops_trace.py b/api/controllers/console/app/ops_trace.py index c3e9ebac1c2aa4..1e96b6f98245e3 100644 --- a/api/controllers/console/app/ops_trace.py +++ b/api/controllers/console/app/ops_trace.py @@ -1,7 +1,7 @@ from flask_restful import Resource, reqparse from controllers.console import api -from controllers.console.app.error import TracingConfigIsExist, TracingConfigNotExist +from controllers.console.app.error import TracingConfigCheckError, TracingConfigIsExist, TracingConfigNotExist from controllers.console.setup import setup_required from controllers.console.wraps import account_initialization_required from libs.login import login_required @@ -49,7 +49,9 @@ def post(self, app_id): ) if not result: raise TracingConfigIsExist() - return {"result": "success"} + if result.get('error'): + raise TracingConfigCheckError() + return result except Exception as e: raise e diff --git a/api/services/ops_trace/ops_trace_service.py b/api/services/ops_trace/ops_trace_service.py index 1f98a3186fa8d7..ec2bc8d50d25b8 100644 --- a/api/services/ops_trace/ops_trace_service.py +++ b/api/services/ops_trace/ops_trace_service.py @@ -71,11 +71,11 @@ def create_tracing_app_config(cls, app_id: str, tracing_provider: str, tracing_c """ if tracing_provider not in [TracingProviderEnum.LANGFUSE.value, TracingProviderEnum.LANGSMITH.value] and tracing_provider != "": - raise {"error": f"Invalid tracing provider: {tracing_provider}"} + return {"error": f"Invalid tracing provider: {tracing_provider}"} # api check if not cls.check_trace_config_is_effective(tracing_config, tracing_provider): - return {"error": "Tracing config is not effective"} + return {"error": "Invalid Credentials"} # check if trace config already exists trace_config_data: TraceAppConfig = db.session.query(TraceAppConfig).filter( @@ -96,7 +96,7 @@ def create_tracing_app_config(cls, app_id: str, tracing_provider: str, tracing_c db.session.add(trace_config_data) db.session.commit() - return trace_config_data.to_dict() + return {"result": "success"} @classmethod def update_tracing_app_config(cls, app_id: str, tracing_provider: str, tracing_config: dict):