I'm having a problem developing a node that makes web service calls.
I'm using:
It is throwing that exception
node-red_1 | 30 Aug 21:21:50 - [red] Uncaught Exception:
node-red_1 | 30 Aug 21:21:50 - TypeError: Cannot set property listening of #<Server> which has only a getter
node-red_1 | at _clone (/usr/src/node-red/node_modules/clone/clone.js:156:16)
node-red_1 | at _clone (/usr/src/node-red/node_modules/clone/clone.js:156:18)
node-red_1 | at _clone (/usr/src/node-red/node_modules/clone/clone.js:156:18)
node-red_1 | at _clone (/usr/src/node-red/node_modules/clone/clone.js:156:18)
node-red_1 | at _clone (/usr/src/node-red/node_modules/clone/clone.js:156:18)
node-red_1 | at clone (/usr/src/node-red/node_modules/clone/clone.js:196:10)
node-red_1 | at Object.cloneMessage (/usr/src/node-red/node_modules/node-red/red/runtime/util.js:53:13)
node-red_1 | at /usr/src/node-red/node_modules/node-red/red/runtime/nodes/flows/Flow.js:262:48
node-red_1 | at Array.forEach (<anonymous>)
node-red_1 | at Flow.handleError (/usr/src/node-red/node_modules/node-red/red/runtime/nodes/flows/Flow.js:256:34)
I have a list of data that I need to POST to a webservice. Everything works fine until I fire my HTTP post. Basically, I have this snippet of code
const objects = msg.payload || []
const hpptCalls = objects.map(obj => (callback) => {
processObject(obj, callback)
})
async.parallelLimit(hpptCalls, 5, (err, results) => {
node.send(msg)
})
Inside my processObject function, I have almost the same code that exists in core node 21-httprequest.js
const req = http.request(options, res => {
let data = ''
res.on('data', chunk => {
data += chunk
})
res.on('end', () => {
callback(null)
})
})
req.setTimeout(120000, () => {
node.error('Error', msg)
req.abort()
callback('Error')
})
req.on('error', err => {
node.error(err, msg)
callback(err)
})
if (content) {
req.write(JSON.stringify(content))
}
req.end()
But, it seems that when the first HTTP post is called, my node-red crash entirely with that exception. I can figure what is the problem. I put a lot o try catches thinking that my code is breaking something, but it is a straightforward code.
Apparently found the problem, as mentioned in project's github. At a random point in the flow, someone put a function node with the following code
return {
"_msg": msg
[other properties]
}
Thanks! (It was hard to find the problem lol, we have a big flow).