Skip to content

Home > @opengovsg/logging > serializeError

serializeError() function ​

The default error serialiser: shapes an already-normalised Error into the flat object emitted as the error wire field. Framework-neutral — it reads no framework-specific fields (e.g. it does **not** map a tRPC code to kind).

Produces { ...ownEnumerableProps, kind, message, stack, cause }: - kind – the error's class name (err.name), Datadog's error.kind facet. - message / stack / cause – the native fields (non-enumerable, so added explicitly rather than via the spread). - any own enumerable properties the error carries (e.g. a tRPC code) survive on the wire under error, just not lifted into kind.

Override via LoggingConfig.serializeError to add framework-specific shaping (e.g. tRPC code → kind, NestJS HttpException).

Signature:

typescript
export declare function serializeError(err: Error): Record<string, unknown>;

Parameters ​

ParameterTypeDescription
errError

Returns:

Record<string, unknown>