0

Is it not possible to stringify error using JSON.stringify?

Also, Object.keys(err) wouldn't show any keys present with Error object.

Other observation: Error object has non standard property "stack" which I am trying to access. Error.prototype.stack provides with stack trace. In my attempts to stringify properties of Error(name, message and stack), any help is appreciated!

Following is the output from Chrome.

  > var err = new Error
    undefined
  > err
    Error
       at <anonymous>:1:11
   JSON.stringify(err)
  > "{}"
Tanvi Patel
  • 1,167
  • 3
  • 11
  • 18
  • 3
    Possible duplicate of [Is it not possible to stringify an Error using JSON.stringify?](https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify) – Jacob Sep 30 '17 at 00:25
  • try `err+""`. is that what you want? – DragonKnight Sep 30 '17 at 01:13

2 Answers2

0

You could use something like this:

    JSON.stringify(error.stack)
-4

How about try something like err.toString()