fix(api): 移除调试日志并改进错误提示

- 移除了 API 请求的调试日志输出
- 优化了错误消息格式,添加了错误码前缀
- 为后端错误响应添加了 toast 提示
- 为网络请求失败添加了 toast 提示
This commit is contained in:
cg
2026-07-17 07:16:14 +08:00
parent 860136bceb
commit a73bd79eb5
+4 -2
View File
@@ -13,7 +13,6 @@ const API_HOST = 'https://dev.wash-painting.cn'
// 参考 goodBooth 项目的 fetchsomething
// ==========================================
function httpRequest(url, params) {
console.log('[API] Request:', params.method, url, 'data:', JSON.stringify(params.data))
return new Promise((resolve, reject) => {
// 自动注入 Authorization token
const headers = Object.assign({}, params.headers || {})
@@ -40,11 +39,14 @@ function httpRequest(url, params) {
uni.reLaunch({ url: '/pages/login/login' })
reject({ msg: '登录已过期,请重新登录' })
} else {
const errMsg = (res.data && res.data.msg) || (res.data && res.data.errmsg) || `请求失败(${code})`
const rawMsg = (res.data && res.data.msg) || (res.data && res.data.errmsg) || '请求失败'
const errMsg = `[${code}] ${rawMsg}`
uni.showToast({ title: errMsg, icon: 'none', duration: 2500 })
reject({ msg: errMsg, code })
}
},
fail: (err) => {
uni.showToast({ title: err.errMsg || '网络请求失败', icon: 'none', duration: 2500 })
reject({ msg: err.errMsg || '网络请求失败' })
}
})