feat: 请求日志 + 前端埋点系统
后端: - 新增 logger 中间件,记录所有请求到 logs/ 目录 - 新增 /api/track 接口接收前端埋点数据 前端: - 新增 tracker 工具,支持页面访问/操作/错误埋点 - request.ts 添加 API 错误自动埋点 - App.vue 初始化全局错误追踪 文档: - CLAUDE.md 更新项目结构 - DEV.md 添加埋点和日志说明
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { API_BASE } from '@/config'
|
||||
import type { LoginResult } from '@/api/auth'
|
||||
import { trackApiError } from './tracker'
|
||||
|
||||
interface RequestOptions {
|
||||
url: string
|
||||
@@ -88,6 +89,8 @@ export function request<T = any>(options: RequestOptions): Promise<T> {
|
||||
if (data.code === 0) {
|
||||
resolve(data.data)
|
||||
} else {
|
||||
// 埋点:API 业务错误
|
||||
trackApiError(options.url, statusCode, data.message || '请求失败')
|
||||
// "用户不存在" 不弹 toast(首次登录竞态)
|
||||
if (data.code !== 40400 || data.message !== '用户不存在') {
|
||||
uni.showToast({ title: data.message || '请求失败', icon: 'none' })
|
||||
@@ -96,6 +99,8 @@ export function request<T = any>(options: RequestOptions): Promise<T> {
|
||||
}
|
||||
},
|
||||
fail: (err: any) => {
|
||||
// 埋点:网络错误
|
||||
trackApiError(options.url, 0, '网络错误')
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
reject(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user