debug: rl_callback添加详细日志和异常捕获
This commit is contained in:
parent
93780ac01d
commit
38cea985f1
@ -1,5 +1,6 @@
|
||||
import json
|
||||
from appPublic.log import debug
|
||||
import traceback
|
||||
from appPublic.log import debug, error
|
||||
|
||||
# Vendor callback: GET or POST
|
||||
# Volcengine example (GET):
|
||||
@ -7,8 +8,10 @@ from appPublic.log import debug
|
||||
# &reqMeasureInfoValue=1&verify_type=real_time
|
||||
# Return format depends on vendor requirements.
|
||||
|
||||
debug("[rl_callback] ===== START =====")
|
||||
debug(f"[rl_callback] params_kw keys: {list(params_kw.keys())}")
|
||||
debug(f"[rl_callback] params_kw: {params_kw}")
|
||||
print(f"[rl_callback] params_kw: {params_kw}")
|
||||
|
||||
body_str = http_request.get("body", "") or ""
|
||||
byted_token = ""
|
||||
@ -20,32 +23,45 @@ try:
|
||||
byted_token = (body.get("BytedToken") or body.get("bytedToken")
|
||||
or body.get("byted_token") or body.get("Token") or "")
|
||||
result_code = body.get("resultCode") or body.get("ResultCode") or ""
|
||||
except:
|
||||
pass
|
||||
debug(f"[rl_callback] from body: byted_token={byted_token}, result_code={result_code}")
|
||||
except Exception as e:
|
||||
error(f"[rl_callback] body parse error: {e}")
|
||||
debug(f"[rl_callback] body parse error: {e}")
|
||||
|
||||
# 2. Fallback: query string params (GET callback)
|
||||
if not byted_token:
|
||||
byted_token = (params_kw.get("bytedToken")
|
||||
or params_kw.get("BytedToken")
|
||||
or params_kw.get("byted_token")
|
||||
or params_kw.get("BytedToken")
|
||||
or "")
|
||||
if not result_code:
|
||||
result_code = params_kw.get("resultCode", "")
|
||||
|
||||
debug(f"[rl_callback] byted_token={byted_token}, resultCode={result_code}")
|
||||
debug(f"[rl_callback] final: byted_token={byted_token}, resultCode={result_code}")
|
||||
print(f"[rl_callback] final: byted_token={byted_token}, resultCode={result_code}")
|
||||
|
||||
if not byted_token:
|
||||
debug("[rl_callback] ERROR: missing bytedToken")
|
||||
return json.dumps({"code": "400", "message": "Missing bytedToken"})
|
||||
|
||||
# Process callback
|
||||
try:
|
||||
debug(f"[rl_callback] calling rl_handle_callback with byted_token={byted_token}")
|
||||
result = await rl_handle_callback(byted_token, project_name="default")
|
||||
|
||||
debug(f"[rl_callback] handle_callback result: {result}")
|
||||
print(f"[rl_callback] handle_callback result: {result}")
|
||||
except Exception as e:
|
||||
error(f"[rl_callback] rl_handle_callback exception: {e}\n{traceback.format_exc()}")
|
||||
debug(f"[rl_callback] rl_handle_callback exception: {e}")
|
||||
print(f"[rl_callback] rl_handle_callback exception: {e}")
|
||||
print(traceback.format_exc())
|
||||
return json.dumps({"code": "500", "message": f"Internal error: {str(e)}"})
|
||||
|
||||
# Volcengine expects HTTP 200 with any body for success.
|
||||
# Return a simple success/failure response.
|
||||
if result.get("success"):
|
||||
debug("[rl_callback] SUCCESS")
|
||||
return json.dumps({"code": "200", "message": "ok"})
|
||||
else:
|
||||
debug(f"[rl_callback] FAILED: {result.get('message', 'unknown')}")
|
||||
return json.dumps({"code": "500", "message": result.get("message", "callback error")})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user