diff --git a/common/api.js b/common/api.js index 9ce7701..40706c2 100644 --- a/common/api.js +++ b/common/api.js @@ -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 || '网络请求失败' }) } })