From 1c59acc72b33f56a62eeade6b9973269bfe38f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=94=B7?= Date: Tue, 28 Apr 2026 00:41:28 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E6=8E=92=E8=AF=BE=20clazz=20API=20?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=BE=93=E5=87=BA=20[ClazzApi]/[Cla?= =?UTF-8?q?zzQuery]=20=E5=88=B0=20vConsole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- src/store/clazz.ts | 38 ++++++++++++++++++++++++++++++++------ src/utils/request.ts | 29 ++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/store/clazz.ts b/src/store/clazz.ts index a3b0f78..bd2af0e 100644 --- a/src/store/clazz.ts +++ b/src/store/clazz.ts @@ -74,7 +74,7 @@ export default function useClazz() { async function query(start_from: string, end_by: string) { let {currentRole, current:{hty_id}} = usingUser.store; load_start() - const {r, d, e} = await request({ + const {r, d, e, statusCode} = await request({ url: "/api/v1/clazz/find_all_non_repeatable_within_date_range_by_hty_id", method: "GET", data: {start_from, end_by, hty_id} }) @@ -91,6 +91,13 @@ export default function useClazz() { return false; }); } else { + console.warn("[ClazzQuery] non_repeatable failed", { + e, + statusCode, + start_from, + end_by, + hty_id, + }); showFailToast(e); } return Promise.resolve(r); @@ -100,7 +107,7 @@ export default function useClazz() { load_start() await Promise.all(hty_ids.map(async hty_id => { - const {r, d, e} = await request({ + const {r, d, e, statusCode} = await request({ url: "/api/v1/clazz/find_all_non_repeatable_within_date_range_by_hty_id", method: "GET", data: {start_from, end_by, hty_id} }) @@ -111,7 +118,13 @@ export default function useClazz() { repeatList: [] } } else { - console.error("query failed...", e) + console.warn("[ClazzQuery] subsidiary non_repeatable failed", { + e, + statusCode, + hty_id, + start_from, + end_by, + }); } })); load_done() @@ -160,7 +173,7 @@ export default function useClazz() { async function query_repeats(start_from: string, end_by: string) { let {current:{hty_id}} = usingUser.store; load_start() - const {r, d, e} = await request({ + const {r, d, e, statusCode} = await request({ url: "/api/v1/clazz/find_all_repeatable_within_date_range_by_hty_id", method: "GET", data: {start_from, end_by, hty_id} }) @@ -169,6 +182,13 @@ export default function useClazz() { const repeatList = normalizeClazzListPayload(d, "query_repeatable"); store.repeatList = repeat_prepare(start_from, end_by, repeatList, store.list); } else { + console.warn("[ClazzQuery] repeatable failed", { + e, + statusCode, + start_from, + end_by, + hty_id, + }); showFailToast(e); } return Promise.resolve(r); @@ -178,7 +198,7 @@ export default function useClazz() { async function query_repeats_for_subsidiaries(start_from: string, end_by: string, hty_ids: string[]) { load_start() await Promise.all(hty_ids.map(async hty_id => { - const {r, d, e} = await request({ + const {r, d, e, statusCode} = await request({ url: "/api/v1/clazz/find_all_repeatable_within_date_range_by_hty_id", method: "GET", data: {start_from, end_by, hty_id} }) @@ -187,7 +207,13 @@ export default function useClazz() { store.subsidiaryClazzByHtyId[hty_id] = store.subsidiaryClazzByHtyId[hty_id] || {list: [], repeatList: []} store.subsidiaryClazzByHtyId[hty_id].repeatList = repeat_prepare(start_from, end_by, repeatList, store.subsidiaryClazzByHtyId[hty_id].list); } else { - console.error("query failed...", e) + console.warn("[ClazzQuery] subsidiary repeatable failed", { + e, + statusCode, + hty_id, + start_from, + end_by, + }); } })) load_done() diff --git a/src/utils/request.ts b/src/utils/request.ts index 8df1138..f26432e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -100,7 +100,7 @@ export default function request({url = '', method = 'get', data, params, ...rest } return axiosInstance.request({url, method, data, params, ...rest}).then(response => { - let {statusText, status, data: res, headers} = response; + let {statusText, status, data: res, headers, config} = response; if (status === 401) { const isCozeRequest = url?.startsWith('/coze'); const rawErr = (res && typeof res === 'object' && (res.e || (res.error && res.error.message))) || 'Login failed'; @@ -161,6 +161,33 @@ export default function request({url = '', method = 'get', data, params, ...rest '接口返回了页面而非 JSON(请确认 Nginx 已将 /api/v1/clazz/ 反代到 htykc)'; } + const finalUrl = (config && typeof config.url === 'string' ? config.url : '') || url || ''; + const isClazzApi = + finalUrl.includes('/api/v1/clazz') || + (typeof url === 'string' && url.includes('/api/v1/clazz')); + if (isClazzApi && (!resolved.r || status >= 400)) { + let bodySnippet = ''; + if (typeof res === 'string') { + bodySnippet = res.slice(0, 240); + } else if (res && typeof res === 'object') { + try { + bodySnippet = JSON.stringify(res).slice(0, 500); + } catch { + bodySnippet = '[object]'; + } + } + console.warn('[ClazzApi]', { + method: (config?.method || method || 'get').toUpperCase(), + url: finalUrl, + httpStatus: status, + statusText, + businessOk: resolved.r, + toastOrErr: resolved.e, + hty_err: resolved.hty_err, + bodySnippet, + }); + } + return Promise.resolve(resolved); }) };