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 0266f9fb65
3 changed files with 11 additions and 3 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__/
*.pyc
*.pyo

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]: