serializeError
serializeError(
error
,options
):SerializedError
Serialize any thrown value into a plain object (SerializedError
).
If the input has already been marked as serialized (via internal marker),
it is returned directly. Otherwise, it traverses cause
, AggregateError
,
and custom properties per options.
Parameters
Section titled “Parameters”unknown
The value to serialize (Error, AggregateError, or any thrown).
options
Section titled “options”ErrorSerialization
= {}
Configuration for recursion, inclusion of cause/stack, etc.
Returns
Section titled “Returns”The structured, plain-object representation of the error.
Example
Section titled “Example”// Simple Errorconst simple = new Error('oops');console.log(serializeError(simple));
// Error with causeconst root = new Error('root');const child = new Error('child', { cause: root });console.log(serializeError(child, { cause: true }));
@example// AggregateError exampleconst agg = new AggregateError([ new Error('a'), new Error('b')], 'multiple');console.log( serializeError(agg, { aggregated: true, stack: false }));