简体   繁体   中英

JSON.stringify missing properties

I'm writing a custom console.error function so that every time an error occurs I receive an e-mail. To send the error in e-mail body I use JSON.stringify() . The problem is that it is missing some properties. See the two images below:

Email: 电子邮件

In console: 在控制台中

And here is how I use JSON.stringfy:

JSON.stringify(arguments, null, 4);

I've been googling and found people with the same issue, but so far no answer.

Could you help me, please?

Edit : See this .

Since your Error object is inside another object, you might have to use 2 stringify calls :

JSON.stringify({
0: ...,
1: JSON.stringify({errorObject, ["message", "arguments", "type", "name"]}),
});

Or something like that.


If I'm getting this correctly, the informations you are lacking are in the Error object. My guess would be that JSON.stringify calls .toString() for each object inside it. Though, for an Error object, maybe the toString() function doesn't return ALL the informations you want, versus what you see in the console.

Maybe you'll have to call the Error object's .description() function yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM