I have an error object which has several properties and looks like this in the console:
But JSON.stringify(event) only results in the string '{"isTrusted":true}, which omits all the important properties I'm looking for.
I've searched for and tried several solutions but none seem to give the expected result:
1.
> JSON.stringify(event, Object.getOwnPropertyNames(event)) < '{"isTrusted":true}' > JSON.stringify(event, (function(seen, k, value) { console.log(`k=${k} value=${value}`); if (typeof value === 'object' && value !== null) { if (seen.indexOf(value) !== -1) return; else seen.push(value); } return value; }).bind(null, [])); < '{"isTrusted":true}' > for(k in event){ console.log(k); } < undefined > event.toString() < '[object ErrorEvent]' > Object.keys(event) < ['isTrusted'] The only thing that seems to work is manually listing the property names I see in the console, and passing that to JSON.stringy as an array explicity:
JSON.stringify(event, ["isTrusted", "bubbles", "cancelBubble", "cancelable", "colno", "composed", "currentTarget", "defaultPrevented", "error", "eventPhase", "filename", "lineno", "message", "returnValue", "srcElement", "target", "timeStamp", "type"]) '{"isTrusted":true,"bubbles":false,"cancelBubble":false,"cancelable":true,"colno":5,"composed":false,"currentTarget":{},"defaultPrevented":false,"error":"{\\"reason\\":\\"GET /problem/8a9463a241657d960a68ca73f2a532f3 failed: 500\\"}","eventPhase":2,"filename":"http://localhost:3000/js/chess.js","lineno":26,"message":"Uncaught {\\"reason\\":\\"GET /problem/8a9463a241657d960a68ca73f2a532f3 failed: 500\\"}","returnValue":true,"srcElement":{},"target":{},"timeStamp":168.59999999403954,"type":"error"}' Doing this feels wrong and I could miss properties that are not in the static list above.
How can I enumerate the same set of object properties I can see in the console?
