oms/backend/app/lib/platformError.js
liufumingren 9f067c1b58 fix(send): 发货回传遇平台 500 时改用实时订单行重发
线上「意洁」全部订单发货回传失败,文案只有 `店管家发货同步失败:12;ErrorCode=500`。
用同一账号对平台做对照实验(真实订单)确认:同一个单用**平台实时订单行**发送
`IsSuccess:true`;用本地快照行但清空 `SubOrders` 则回
`{"Success":false,"ErrorCode":"500","Message":"服务器繁忙,请稍会儿再试."}`。
即 500 是「平台没解析订单报文」,与订单业务状态无关。

- 新增 lib/platformError.isPayloadRejected:ErrorCode>=500 / 服务器繁忙 / 系统异常 /
  Message 只有一串数字 → 报文类失败;业务类(不是待发货、都没打印、风控拦截、请先勾选)与限流不算
- resolveSendRow:本地快照拼出的行若 SubOrders 为空则不使用,改回读平台实时订单行(warn 留痕)
- syncOrder:命中报文类失败时用 forceRemote 回读订单行重发一次,成功即置「已同步」
- recordFailure:把平台原始返回写进日志,便于下次直接定位缺了哪个字段
- 单测 platformError.test.js;文档补 §2.1.1(对照实验表 + 兜底三步)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 22:04:37 +08:00

30 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 平台响应「报文不被接受」判定(外部打单平台通用)
*
* 实测店管家(2026-11-07):`Orders[i][SubOrders]` 为空时直接
* `{"Success":false,"ErrorCode":"500","Message":"服务器繁忙,请稍会儿再试."}`;
* 线上还出现过 `Message` 只回一串数字的兜底文案(`店管家发货同步失败:12;ErrorCode=500`)。
* 这类失败与订单业务状态无关,是平台没能解析我们提交的报文,
* 改用平台实时订单行重发通常即可成功(由调用方决定是否重试)。
*/
/**
* @param {Object|null} json 平台响应
* @param {string} [message] 已拼好的错误文案
* @return {boolean} 是否为报文类失败
*/
function isPayloadRejected(json, message = '') {
if (!json || typeof json !== 'object') return false;
const message0 = json.Message == null ? '' : String(json.Message);
const text = `${message0} ${message || ''}`;
const code = Number(json.ErrorCode);
if (Number.isFinite(code) && code >= 500) return true;
if (/服务器繁忙|系统异常/.test(text)) return true;
// Message 只有一串数字:服务端异常兜底文案,不是业务原因
return /^\s*[0-9]{1,6}\s*$/.test(message0);
}
module.exports = { isPayloadRejected };