update
This commit is contained in:
@@ -526,36 +526,15 @@ async function smartunpack(msg, options = {}) {
|
||||
max_delay = 5000
|
||||
} = options;
|
||||
|
||||
// Handle both raw JSON strings and transport message objects
|
||||
let payload;
|
||||
if (typeof msg === 'string') {
|
||||
payload = msg;
|
||||
} else if (msg !== null && typeof msg === 'object') {
|
||||
if (msg.data !== undefined) {
|
||||
payload = typeof msg.data === 'string' ? msg.data : new TextDecoder().decode(msg.data);
|
||||
} else if (msg.payload !== undefined) {
|
||||
payload = typeof msg.payload === 'string' ? msg.payload : new TextDecoder().decode(msg.payload);
|
||||
} else {
|
||||
throw new Error('Message has neither data nor payload property');
|
||||
}
|
||||
let envJsonObj;
|
||||
|
||||
// NATS's Javascript lib already return JSON object
|
||||
if (msg !== null && typeof msg === 'object') {
|
||||
envJsonObj = msg;
|
||||
} else {
|
||||
throw new Error('Invalid message format: expected JSON string or message object');
|
||||
}
|
||||
|
||||
logTrace('smartunpack', `smartunpack: raw payload length=${payload.length}`);
|
||||
|
||||
// Debug: Show first 200 chars of payload
|
||||
const payloadPreview = payload.substring(0, 200);
|
||||
logTrace('smartunpack', `smartunpack: payload preview: ${payloadPreview}`);
|
||||
|
||||
let envJsonObj;
|
||||
try {
|
||||
envJsonObj = JSON.parse(payload);
|
||||
} catch (e) {
|
||||
logTrace('smartunpack', `smartunpack: JSON parse failed: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
logTrace(envJsonObj.correlation_id, 'Processing received message');
|
||||
logTrace(envJsonObj.correlation_id, `smartunpack: envelope has ${envJsonObj.payloads.length} payloads`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user