diff --git a/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts b/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts index 935cb4fe40..4a882bdcbe 100644 --- a/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts +++ b/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts @@ -209,9 +209,9 @@ export class KafkaTrigger implements INodeType { } catch (error) { } } - if (options.returnHeaders) { + if (options.returnHeaders && message.headers) { const headers: {[key: string]: string} = {}; - for (const key in message.headers) { + for (const key of Object.keys(message.headers)) { const header = message.headers[key]; headers[key] = header?.toString('utf8') || ''; }