修复数字员工同步业务失败识别
This commit is contained in:
@@ -96,6 +96,8 @@ interface SyncAck {
|
||||
|
||||
interface SyncResponse {
|
||||
success?: boolean;
|
||||
code?: string | number;
|
||||
status?: string | number;
|
||||
acked?: SyncAck[];
|
||||
data?: {
|
||||
acked?: SyncAck[];
|
||||
@@ -185,9 +187,8 @@ export async function flushDigitalEmployeeSyncOutbox(
|
||||
const response = await postOutbox(config, rows);
|
||||
const finishedAt = new Date().toISOString();
|
||||
const acked = response.data?.acked || response.acked || [];
|
||||
if (response.success === false) {
|
||||
throw new Error(response.message || "digital employee sync rejected");
|
||||
}
|
||||
const responseError = readSyncResponseError(response);
|
||||
if (responseError) throw new Error(responseError);
|
||||
const syncedRows = acked.length > 0
|
||||
? rows.filter((row) => acked.some((ack) => ackMatchesRow(ack, row)))
|
||||
: rows;
|
||||
@@ -236,6 +237,35 @@ export async function flushDigitalEmployeeSyncOutbox(
|
||||
return getDigitalEmployeeSyncStatus();
|
||||
}
|
||||
|
||||
function readSyncResponseError(response: SyncResponse): string | null {
|
||||
if (response.success === false) {
|
||||
return response.message || "digital employee sync rejected";
|
||||
}
|
||||
|
||||
const code = normalizeResponseCode(response.code);
|
||||
if (code && code !== "0000") {
|
||||
return response.message || `digital employee sync rejected: ${code}`;
|
||||
}
|
||||
|
||||
const status = normalizeResponseCode(response.status);
|
||||
if (status && ["error", "fail", "failed", "failure"].includes(status.toLowerCase())) {
|
||||
return response.message || "digital employee sync rejected";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizeResponseCode(value: unknown): string | null {
|
||||
if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
return trimmed || null;
|
||||
}
|
||||
if (typeof value === "number" && Number.isFinite(value)) {
|
||||
return String(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveSyncConfig(): DigitalEmployeeSyncConfig {
|
||||
const config = (readSetting("digital_employee_sync_config") || {}) as Record<
|
||||
string,
|
||||
|
||||
Reference in New Issue
Block a user