feat(ops): add client error reporting API and frontend hooks

Collect mini-user/shop/partner JS errors via POST /common/client-errors, persist logs, and push fatal/error to WeCom.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-02 16:27:08 +08:00
parent 3328c52cb4
commit 205c1110c2
11 changed files with 520 additions and 0 deletions
+11
View File
@@ -917,6 +917,17 @@ C 端「联系客服 → 在线客服」跳转企业微信 **微信客服** 链
| 核销 | 金额 `<1``>1000` 元;1 分钟尝试 `>3`1 分钟失败 `>5`;弱网达阈值;新建补核销待办 |
| 订单 | 超时未关待付款;待发货 >24h;配送中 >48h(每 5 分钟扫描) |
| 运维 | MySQL/Redis 探活失败;结算 Cron 失败;新建售后/技术支持工单 |
| 客户端 | `POST /api/v1/common/client-errors``fatal`→P0、`error`→P1`warn` 只记日志/落库不推群 |
#### 客户端报错上报
| 项 | 说明 |
|----|------|
| 接口 | `POST /api/v1/common/client-errors`(可匿名;带 JWT 时附带用户身份) |
| Body | `level`fatal/error/warn)、`category`js_error / unhandled_rejection / api_error / network / render / bridge / other)、`message`、可选 `stack` / `pagePath` / `clientApp` / `extra` |
| 日志 | Nest `Logger``[client_error]`;并写入 `log_user_analytics``event_name=client_error` |
| 企微 | 仅 `fatal`/`error`;同指纹 10 分钟去重 |
| 前端 | mini-user、`h5-shop``h5-partner` 启动时 `installClientErrorReporting()`:全局 `error` / `unhandledrejection`mini-user 另挂 Taro 钩子) |
告警经 Redis 去重(同指纹默认 10 分钟内不重复推);**只通知、不拦截**交易与核销。Webhook key 泄露时在企微后台重置机器人并更新 `.env`