Last active
April 5, 2020 12:49
-
-
Save talkol/db08320f009d8b792f5947bedd155a79 to your computer and use it in GitHub Desktop.
Stringify JavaScript Errors that may be of unknown type (string, object, etc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// always returns a simple string, can take unknown types and strange objects as input | |
function stringifyError(err) { | |
if (err instanceof Object) return JSON.stringify(err, Object.getOwnPropertyNames(err)); | |
else return err.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment