fix(waybill): 取号失败时把平台错误信息返回给 WMS
- 新增 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>
This commit is contained in:
parent
ba0d03414a
commit
5f605b5412
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user