fix(api): 移除调试日志并改进错误提示
- 移除了 API 请求的调试日志输出 - 优化了错误消息格式,添加了错误码前缀 - 为后端错误响应添加了 toast 提示 - 为网络请求失败添加了 toast 提示
This commit is contained in:
+4
-2
@@ -13,7 +13,6 @@ const API_HOST = 'https://dev.wash-painting.cn'
|
|||||||
// 参考 goodBooth 项目的 fetchsomething
|
// 参考 goodBooth 项目的 fetchsomething
|
||||||
// ==========================================
|
// ==========================================
|
||||||
function httpRequest(url, params) {
|
function httpRequest(url, params) {
|
||||||
console.log('[API] Request:', params.method, url, 'data:', JSON.stringify(params.data))
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 自动注入 Authorization token
|
// 自动注入 Authorization token
|
||||||
const headers = Object.assign({}, params.headers || {})
|
const headers = Object.assign({}, params.headers || {})
|
||||||
@@ -40,11 +39,14 @@ function httpRequest(url, params) {
|
|||||||
uni.reLaunch({ url: '/pages/login/login' })
|
uni.reLaunch({ url: '/pages/login/login' })
|
||||||
reject({ msg: '登录已过期,请重新登录' })
|
reject({ msg: '登录已过期,请重新登录' })
|
||||||
} else {
|
} 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 })
|
reject({ msg: errMsg, code })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
|
uni.showToast({ title: err.errMsg || '网络请求失败', icon: 'none', duration: 2500 })
|
||||||
reject({ msg: err.errMsg || '网络请求失败' })
|
reject({ msg: err.errMsg || '网络请求失败' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user