javascript-stringify icon indicating copy to clipboard operation
javascript-stringify copied to clipboard

Handle different error types

Open Munter opened this issue 3 years ago • 0 comments

Currently, all error types seem to be represented as new Error(<message>). Other error types like SyntaxError, ReferenceError etc, are not serialized any differently

Suggestion:

stringify(new SyntaxError('syntax')); // "new SyntaxError(syntax')"
stringify(new ReferenceError('syntax')); // "new ReferenceError(syntax')"
...

It should be possible to do this using Error.prototype.name with the caveat that it can be overridden to an empty string, which should probably be handled

Munter avatar Mar 24 '21 08:03 Munter