From efae461f9d0b142e0877e4f4c005d91621f6818d Mon Sep 17 00:00:00 2001 From: ltx <19304474232@163.com> Date: Fri, 10 Apr 2026 01:54:11 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E6=8F=90=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/http.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/http.js b/utils/http.js index 413f3f2..435c190 100644 --- a/utils/http.js +++ b/utils/http.js @@ -143,6 +143,7 @@ function request({ // 如果后端在 Response Headers 下发新的 token,就替换本地 token const tokenUpdated = tryUpdateAccessTokenFromResponseHeaders(res); const statusCode = res && res.data && res.data.statusCode ? res.data.statusCode : 0; + const errors = res && res.data && res.data.errors ? res.data.errors : null; const payload = res && res.data !== undefined ? res.data : null; // ── 401 未授权:尝试刷新Token ── @@ -201,28 +202,28 @@ function request({ // ── 403 禁止访问 ── if (statusCode === 403) { - wx.showToast({ title: '无访问权限', icon: 'none' }); + wx.showToast({ title: errors, icon: 'none' }); reject(new Error('Forbidden')); return; } // ── 404 资源不存在 ─────────────────────────────────────────── if (statusCode === 404) { - wx.showToast({ title: '请求资源不存在', icon: 'none' }); + wx.showToast({ title: errors || '请求资源不存在', icon: 'none' }); reject(new Error('Not Found')); return; } // ── 5xx 服务端错误 ─────────────────────────────────────────── if (statusCode >= 500) { - wx.showToast({ title: '服务器异常,请稍后重试', icon: 'none' }); + wx.showToast({ title: errors || '服务器异常,请稍后重试', icon: 'none' }); reject(new Error(`Server Error: ${statusCode}`)); return; } // ── 其他非 2xx ─────────────────────────────────────────────── if (statusCode !== 0 && (statusCode < 200 || statusCode >= 300)) { - wx.showToast({ title: `请求失败(${statusCode})`, icon: 'none' }); + wx.showToast({ title: errors || `请求失败(${statusCode})`, icon: 'none' }); reject(new Error(`HTTP Error: ${statusCode}`)); return; }