From f6cbd7993f36e2f5834a7c7db50d8cf666f5f755 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Tue, 7 Jul 2026 21:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BF=AB=E6=89=8B=E8=A1=8C?= =?UTF-8?q?=E4=B8=9A=E5=9B=9E=E8=B0=83=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consume-callback-service.ts | 34 ++++++++++++++++--- .../destroy-callback-service.ts | 34 ++++++++++++++++--- .../send-callback-service.ts | 34 ++++++++++++++++--- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/apps/backend/src/services/platforms/kuaishou-industry/consume-callback-service.ts b/apps/backend/src/services/platforms/kuaishou-industry/consume-callback-service.ts index 0c115783..1223aa24 100644 --- a/apps/backend/src/services/platforms/kuaishou-industry/consume-callback-service.ts +++ b/apps/backend/src/services/platforms/kuaishou-industry/consume-callback-service.ts @@ -5,7 +5,7 @@ import { getKuaishouIndustryConfig } from './config.js' type JsonObject = Record -const KUAISHOU_OPEN_API = 'https://openapi.kuaixiaodian.com' +const KUAISHOU_OPEN_API = 'https://openapi.kwaixiaodian.com' type ConsumeCallbackInput = { oid: string @@ -128,9 +128,7 @@ export async function consumeCallback(input: ConsumeCallbackInput): Promise<{ su return { success: ok, response: json } } catch (err) { const message = err instanceof Error ? err.message : String(err) - logWarn('[kuaishou-industry/consume-callback]', `核销回调异常 oid=${input.oid}`, { - error: message, - }) + logWarn('[kuaishou-industry/consume-callback]', `核销回调异常 oid=${input.oid}`, resolveCallbackErrorDetail(err)) return { success: false, error: message } } } @@ -156,3 +154,31 @@ function stringifySignValue(value: unknown): string { if (typeof value === 'object') return JSON.stringify(value, Object.keys(value as Record).sort()) return String(value) } + +function resolveCallbackErrorDetail(error: unknown): JsonObject { + const detail: JsonObject = { + error: error instanceof Error ? error.message : String(error), + } + const cause = error && typeof error === 'object' && 'cause' in error + ? (error as { cause?: unknown }).cause + : null + if (!cause || typeof cause !== 'object') { + return detail + } + + const current = cause as Record + const fields: Array<[string, unknown]> = [ + ['causeMessage', current.message], + ['causeCode', current.code], + ['causeSyscall', current.syscall], + ['causeHostname', current.hostname], + ] + for (const [key, value] of fields) { + const text = String(value || '').trim() + if (text) { + detail[key] = text + } + } + + return detail +} diff --git a/apps/backend/src/services/platforms/kuaishou-industry/destroy-callback-service.ts b/apps/backend/src/services/platforms/kuaishou-industry/destroy-callback-service.ts index 3a950541..de6abf3e 100644 --- a/apps/backend/src/services/platforms/kuaishou-industry/destroy-callback-service.ts +++ b/apps/backend/src/services/platforms/kuaishou-industry/destroy-callback-service.ts @@ -5,7 +5,7 @@ import { getKuaishouIndustryConfig } from './config.js' type JsonObject = Record -const KUAISHOU_OPEN_API = 'https://openapi.kuaixiaodian.com' +const KUAISHOU_OPEN_API = 'https://openapi.kwaixiaodian.com' type DestroyCallbackInput = { oid: string @@ -110,9 +110,7 @@ export async function destroyCallback(input: DestroyCallbackInput): Promise<{ su return { success: ok, response: json } } catch (err) { const message = err instanceof Error ? err.message : String(err) - logWarn('[kuaishou-industry/destroy-callback]', `销毁回调异常 oid=${input.oid}`, { - error: message, - }) + logWarn('[kuaishou-industry/destroy-callback]', `销毁回调异常 oid=${input.oid}`, resolveCallbackErrorDetail(err)) return { success: false, error: message } } } @@ -138,3 +136,31 @@ function stringifySignValue(value: unknown): string { if (typeof value === 'object') return JSON.stringify(value, Object.keys(value as Record).sort()) return String(value) } + +function resolveCallbackErrorDetail(error: unknown): JsonObject { + const detail: JsonObject = { + error: error instanceof Error ? error.message : String(error), + } + const cause = error && typeof error === 'object' && 'cause' in error + ? (error as { cause?: unknown }).cause + : null + if (!cause || typeof cause !== 'object') { + return detail + } + + const current = cause as Record + const fields: Array<[string, unknown]> = [ + ['causeMessage', current.message], + ['causeCode', current.code], + ['causeSyscall', current.syscall], + ['causeHostname', current.hostname], + ] + for (const [key, value] of fields) { + const text = String(value || '').trim() + if (text) { + detail[key] = text + } + } + + return detail +} diff --git a/apps/backend/src/services/platforms/kuaishou-industry/send-callback-service.ts b/apps/backend/src/services/platforms/kuaishou-industry/send-callback-service.ts index bbeead8c..c95eda63 100644 --- a/apps/backend/src/services/platforms/kuaishou-industry/send-callback-service.ts +++ b/apps/backend/src/services/platforms/kuaishou-industry/send-callback-service.ts @@ -5,7 +5,7 @@ import { getKuaishouIndustryConfig } from './config.js' type JsonObject = Record -const KUAISHOU_OPEN_API = 'https://openapi.kuaixiaodian.com' +const KUAISHOU_OPEN_API = 'https://openapi.kwaixiaodian.com' type SendCallbackInput = { oid: string @@ -122,9 +122,7 @@ export async function sendCallback(input: SendCallbackInput): Promise<{ success: return { success: ok, response: json } } catch (err) { const message = err instanceof Error ? err.message : String(err) - logWarn('[kuaishou-industry/send-callback]', `发码回调异常 oid=${input.oid}`, { - error: message, - }) + logWarn('[kuaishou-industry/send-callback]', `发码回调异常 oid=${input.oid}`, resolveCallbackErrorDetail(err)) return { success: false, error: message } } } @@ -150,3 +148,31 @@ function stringifySignValue(value: unknown): string { if (typeof value === 'object') return JSON.stringify(value, Object.keys(value as Record).sort()) return String(value) } + +function resolveCallbackErrorDetail(error: unknown): JsonObject { + const detail: JsonObject = { + error: error instanceof Error ? error.message : String(error), + } + const cause = error && typeof error === 'object' && 'cause' in error + ? (error as { cause?: unknown }).cause + : null + if (!cause || typeof cause !== 'object') { + return detail + } + + const current = cause as Record + const fields: Array<[string, unknown]> = [ + ['causeMessage', current.message], + ['causeCode', current.code], + ['causeSyscall', current.syscall], + ['causeHostname', current.hostname], + ] + for (const [key, value] of fields) { + const text = String(value || '').trim() + if (text) { + detail[key] = text + } + } + + return detail +}