From ac40a080219062ad8f3ae366f9398b5ec6556247 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 22 Jul 2026 11:49:24 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E6=89=80=E6=9C=89try/except=E5=8A=A0e?= =?UTF-8?q?xception=E6=97=A5=E5=BF=97,=E5=8F=AF=E8=BF=BD=E8=B8=AAAPI?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E7=9C=9F=E6=AD=A3=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sage_datamart/init.py | 104 +++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/sage_datamart/init.py b/sage_datamart/init.py index bb25044..1f10c9d 100644 --- a/sage_datamart/init.py +++ b/sage_datamart/init.py @@ -40,7 +40,9 @@ async def _resolve_view(request): else recs[0].get('org_type', '')) if org_type == 'reseller': scope = DISTRIBUTOR - except Exception: + except Exception as e: + debug("sage_datamart _resolve_view error: " + str(e)) + pass return scope, org_filter @@ -62,7 +64,9 @@ async def api_model_perf(sor, params_kw=None): sql += " ORDER BY total_calls DESC LIMIT 50" rows = await sor.sqlExe(sql, ns) return [dict(r) for r in rows] - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -81,7 +85,9 @@ async def api_provider_roi(sor, params_kw=None): sql += " ORDER BY total_amount DESC LIMIT 50" rows = await sor.sqlExe(sql, ns) return [dict(r) for r in rows] - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -98,7 +104,9 @@ async def api_stats(request): 'fail_count': await get_fail_count(env, sor), 'active_users': await get_active_users(env, sor), } - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return {} @@ -107,7 +115,9 @@ async def api_top_models(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_top_models(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -116,7 +126,9 @@ async def api_top_providers(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_top_providers(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -125,7 +137,9 @@ async def api_top_users(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_top_users(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -138,7 +152,9 @@ async def api_customer_models(request): 'daily': await get_customer_daily_models(env, sor, userorgid), 'monthly': await get_customer_monthly_models(env, sor, userorgid), } - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return {'daily': [], 'monthly': []} @@ -147,7 +163,9 @@ async def api_daily_trend(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_daily_trend(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -156,7 +174,9 @@ async def api_hourly_concurrency(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_hourly_concurrency(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -165,7 +185,9 @@ async def api_currency_stats(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_currency_breakdown(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -200,7 +222,9 @@ async def api_realtime_cards(request): 'success_rate': await get_scoped_success_rate(sor, today, scope, org_filter), 'fail_count': await get_scoped_fail_count(sor, today, scope, org_filter), } - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return {} @@ -213,7 +237,9 @@ async def api_distributor_customers(request): scope, org_filter = await _resolve_view(request) async with get_sor_context(env, MODULE_NAME) as sor: return await get_distributor_top_customers(sor, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return [] @@ -226,7 +252,9 @@ async def j2_realtime_calls(request): today = env.curDateString() async with get_sor_context(env, MODULE_NAME) as sor: return await get_realtime_calls(sor, today, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -237,7 +265,9 @@ async def j2_realtime_amount(request): today = env.curDateString() async with get_sor_context(env, MODULE_NAME) as sor: return await get_realtime_amount(sor, today, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -249,7 +279,9 @@ async def j2_total_users(request): if scope == DISTRIBUTOR: return await get_distributor_customers_count(sor, org_filter) return await get_total_users_count(sor, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -262,7 +294,9 @@ async def j2_active_today(request): if scope == DISTRIBUTOR: return await get_distributor_active_customers(sor, today, org_filter) return await get_realtime_active_users(sor, today, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -270,7 +304,9 @@ async def j2_online_users(request): try: env = request._run_ns return await get_online_users(env) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -281,7 +317,9 @@ async def j2_scoped_success_rate(request): today = env.curDateString() async with get_sor_context(env, MODULE_NAME) as sor: return await get_scoped_success_rate(sor, today, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -292,7 +330,9 @@ async def j2_scoped_fail_count(request): today = env.curDateString() async with get_sor_context(env, MODULE_NAME) as sor: return await get_scoped_fail_count(sor, today, scope, org_filter) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -303,7 +343,9 @@ async def j2_today_usage(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_today_usage(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -312,7 +354,9 @@ async def j2_today_amount(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_today_amount(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -321,7 +365,9 @@ async def j2_active_users(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_active_users(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -330,7 +376,9 @@ async def j2_fail_count(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_fail_count(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -339,7 +387,9 @@ async def j2_success_rate(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_success_rate(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0 @@ -348,7 +398,9 @@ async def j2_avg_ttft(request): env = request._run_ns async with get_sor_context(env, MODULE_NAME) as sor: return await get_avg_ttft(env, sor) - except Exception: + except Exception as e: + debug("sage_datamart API error: " + str(e)) + return 0