Skip to content

Instantly share code, notes, and snippets.

@talkol
Last active April 5, 2020 12:49
Show Gist options
  • Save talkol/db08320f009d8b792f5947bedd155a79 to your computer and use it in GitHub Desktop.
Save talkol/db08320f009d8b792f5947bedd155a79 to your computer and use it in GitHub Desktop.
Stringify JavaScript Errors that may be of unknown type (string, object, etc)
// 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