`Error` objects are serialized to `{}`
wujekbogdan opened this issue · comments
wujekbogdan commented
When I do:
import serializeJavascript from 'serialize-javascript';
const serialized = serializeJavascript({ error: new Error('message') });
console.log(serialized);
I'm receiving:
"{\"error\":{}}"
Is it intentional or is it a bug?
Sid Chang commented
I have reviewed the code, and currently, only deal with the following types:
RegExp,
Date,
Map,
Set,
Array,
URL,
function,
undefined,
number,
bigint
Error
Object was not handled.
If you feel the need, you can try to add it, and I will also try it too.
Ryuichi Okumura commented
patches welcome!
wujekbogdan commented
I guess it happens because Error
object properties are not enumerable. There's a lib serialize-error
that solves this issue.
Sid Chang commented