Serialize an Error object into a plain object.
null, undefined, strings, numbers, etc.) and functions are wrapped in a NonError error and serialized.[object Buffer]..toJSON() method, then it's called instead of serializing the object's properties..toJSON() implementation to handle circular references and enumerability of the properties.Optionaloptions: Optionsimport {serializeError} from 'serialize-error';
const error = new Error('🦄');
console.log(error);
//=> [Error: 🦄]
console.log(serializeError(error));
//=> {name: 'Error', message: '🦄', stack: 'Error: 🦄\n at Object.<anonymous> …'}
Re-export of serialize-error library for serializing Error objects to JSON.
See
https://github.com/sindresorhus/serialize-error