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> …'}
Serialize an
Errorobject into a plain object.[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.