fix(wechat): handle API errors instead of silently returning null h5_url

- Check HTTP status code, raise exception on non-200
- Raise exception if h5_url missing from response
- Fix description field to use .get() instead of direct key access
- Remove unreachable return None

Previously WeChat API errors (param errors, amount issues, etc.)
would return None, causing the frontend to show:
  https://token.opencomputing.cn/null
Now errors are properly raised and shown to the user.
This commit is contained in:
yumoqing 2026-07-15 16:29:52 +08:00
parent ccee3ba12b
commit 95432431e5
14 changed files with 8 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -172,9 +172,14 @@ class WechatGateway(Gateway):
"Content-Type": "application/json"
}) as resp:
ret = await resp.json()
return ret.get("h5_url")
return None
if resp.status != 200:
err_code = ret.get("code", "UNKNOWN")
err_msg = ret.get("message", str(ret))
raise Exception(f"WeChat API error (HTTP {resp.status}): [{err_code}] {err_msg}")
h5_url = ret.get("h5_url")
if not h5_url:
raise Exception(f"WeChat API response missing h5_url: {json.dumps(ret, ensure_ascii=False)}")
return h5_url
# -----------------------------------------------------
async def refund(self, payload: Dict[str, Any]) -> Dict[str, Any]: