From 5f605b5412989efa2fba3af2cbd4c03fb8432020 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sat, 7 Nov 2026 01:18:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(waybill):=20=E5=8F=96=E5=8F=B7=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E6=8A=8A=E5=B9=B3=E5=8F=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BF=94=E5=9B=9E=E7=BB=99=20WMS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 describePlatformFailure:把平台原始返回里可读的字段(ErrorCode / Message / Data.ErrorMsg / 网点 BranchName)拼进逐单 message,不再只回一个「模板校验失败:2」; 不包含收件人信息,最长 500 字,与已有文案重复的字段自动跳过 - 同一个文案写入 waybill_fetch_records.error_message,raw_response 仍整包落库便于排查 - 实测:淘宝模板 + 1688 订单取号返回「店管家模板校验失败:2(网点:荔湾和平)」, 取号记录与返回 WMS 的信息一致(逐单 success/message 结构未变) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/lib/waybillGet.js | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/backend/app/lib/waybillGet.js b/backend/app/lib/waybillGet.js index eecd95e..ec0a8c2 100644 --- a/backend/app/lib/waybillGet.js +++ b/backend/app/lib/waybillGet.js @@ -230,6 +230,39 @@ function fail(code, message) { return { delivery_order_code: code || '', success: false, message }; } +/** + * 把平台返回的原始错误拼成一句可读提示(回给 WMS,同时写进取号记录) + * + * 平台(店管家)失败时通常只回一个 `ErrorCode`(如 2),真实原因在 `Data.ErrorMsg` / `Data.BranchName` 里, + * WMS 侧只能看到我们给出的文案,所以这里把可读字段一并带上,便于直接定位 + * (不包含任何收件人信息)。 + * @param {Error|Object} err 平台异常(可带 rawResponse) + * @return {string} 失败原因 + */ +function describePlatformFailure(err) { + const message = String((err && err.message) || '取号失败'); + const raw = err && err.rawResponse; + if (!raw || typeof raw !== 'object') return message; + + const parts = []; + const push = (label, value) => { + const text = String(value == null ? '' : value).trim(); + if (!text || text === 'null' || text === 'undefined') return; + if (message.includes(text) || parts.some(item => item.endsWith(`:${text}`))) return; + parts.push(`${label}:${text}`); + }; + + push('平台错误码', raw.ErrorCode); + push('平台提示', raw.Message); + const data = Array.isArray(raw.Data) ? raw.Data[0] : raw.Data; + if (data && typeof data === 'object') { + push('平台说明', data.ErrorMsg || data.Message); + push('网点', data.BranchName); + } + if (!parts.length) return message; + return `${message}(${parts.join(',')})`.slice(0, 500); +} + /** * 组装「未绑定到快递接口」的简短提示 * @@ -571,7 +604,8 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, ctx.logger.warn('[waybill.get] 取号失败 %s:%s', code, err.message); // 平台异常时保留原始返回,便于在取号记录里看到平台到底回了什么 if (err && err.rawResponse) detail.raw = err.rawResponse; - return fail(code, err.message || '取号失败'); + // 回给 WMS 的错误信息带上平台的可读原因(ErrorCode / ErrorMsg / 网点),方便对方直接定位 + return fail(code, describePlatformFailure(err)); } }