3

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: Email

In console: 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?

André Luiz
  • 6,642
  • 9
  • 55
  • 105
  • 6
    A tip: copy and paste text instead of providing pictures of text. It not only helps protect against future image removal, but it also improves searchability. – mscdex Feb 18 '16 at 16:52
  • Which properties is it missing? –  Feb 18 '16 at 17:01
  • 1
    the `[Error: ER_PARSE_ERROR:` portion, which isn't a property – Kevin B Feb 18 '16 at 17:02
  • How was the text in the Terminal screenshot generated? It's not in double quotes, and its neither key nor value in `{"key": "value"}` – prototype Feb 18 '16 at 17:09

1 Answers1

2

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.

Community
  • 1
  • 1
phenxd
  • 689
  • 4
  • 17