Closed GrimbiXcode closed 3 years ago
Hi @GrimbiXcode, Many thanks for the PR!
I finally managed it with this function that seems a little more bulletproof:
isAnObject = (value) => (value && typeof value === 'object' && (value.__proto__ == null || value.__proto__ === Object.prototype));
Hi @Bacto, I have seen, thank you. Unfortunately this still does not work for me. My input from my function node:
msg.payload = {
name: "Tester",
age: 56,
};
After this, I added the following code above your function to get the reason of the error:
try {
console.log(`-- ${typeof msg.payload === 'object'}`)
console.log(`-- ${msg.payload.__proto__ === Object.prototype}`)
console.log(`-- ${msg.payload.__proto__ == null}`)
console.log(`-- ${!!msg.payload}`)
} catch (e) {
console.log(`-EE- ${e}`)
}
.. and I got the following output:
-- true // typeof msg.payload === 'object' => makes sense
-- false // msg.payload.__proto__ === Object.prototype => that makes no sense to me
-- false // msg.payload.__proto__ == null => makes sense
-- true // !!msg.payload => makes sense
Maybe you can do more with it than I can.
Ok so it worked using the "inject" node but not using a function node. Thanks for the example! I've corrected it and published 1.0.5 :)
Wow, that was fast. Thanks a lot!
Description / reason:
The current check if the payload is an object leads to errors despite correct payload.
Improvement:
Way of checking if the payload is an object.