
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
@dotcom-reliability-kit/serialize-error
Advanced tools
A utility function to serialize an error object in a way that's friendly to loggers, view engines, and converting to JSON
A utility function to serialize an error object in a way that's friendly to loggers, view engines, and converting to JSON. This module is part of FT.com Reliability Kit.
Install @dotcom-reliability-kit/serialize-error as a dependency:
npm install --save @dotcom-reliability-kit/serialize-error
Include in your code:
import serializeError from '@dotcom-reliability-kit/serialize-error';
// or
const serializeError = require('@dotcom-reliability-kit/serialize-error');
serializeErrorThe serializeError function accepts an error-like object (e.g. an instance of Error or an object with a message property) and returns a plain JavaScript object (conforming to the SerializedError type) which contains the relevant properties:
serializeError(new Error('example message'));
// {
// fingerprint: '...',
// name: 'Error',
// code: 'UNKNOWN',
// message: 'An error occurred',
// isOperational: false,
// relatesToSystems: [],
// cause: null,
// stack: '...',
// statusCode: null,
// data: {}
// }
You can also pass in a plain object if you already have one that looks like an error (e.g. from a JSON API response):
serializeError({
message: 'example message'
});
SerializedError typeThe SerializedError type documents the return value of the serializeError function. It will always have the following properties, extracting them from a given error object.
SerializedError.fingerprintThis is a hash of the first part of the error stack, used to help group errors that occurred in the same part of the codebase. The fingerprint is null if the error does not include a stack trace.
[!WARNING]
Do not rely on the format or length of the error fingerprint as the underlying hash may change without warning. You can rely on the fingerprint being unique to the type of error being thrown.
SerializedError.nameThis is extracted from the error.name property and is always cast to a String. It defaults to "Error".
SerializedError.codeThis is extracted from the error.code property and is always cast to a String. It defaults to "UNKNOWN".
SerializedError.messageThis is extracted from the error.message property and is always cast to a String. It defaults to "An error occurred", which is not very helpful but we want this library to be resilient to unexpected input data.
SerializedError.isOperationalThis indicates whether the error is operational (known about). See the documentation for OperationalError for more information. It is extracted from the error.isOperational property. It is always cast to a Boolean and defaults to false.
SerializedError.relatesToSystemsThis array contains a list of system codes which are related to the error. It defaults to an empty array.
SerializedError.causeThis is an error instance extracted from the error.cause property, which is serialized before being assigned. It defaults to null.
SerializedError.errorsThis is an array of error instances extracted from the error.errors property (e.g. from an AggregateError). The errors are serialized before being assigned.
SerializedError.stackThis is extracted from the error.stack property. If this property is not a string, then it will default to null.
SerializedError.statusCodeThis is extracted from the error.statusCode property first, then the error.status property otherwise (we use look at both properties to maintain compatibility with third-party request and error libraries). These are always cast to a Number and this property defaults to null.
SerializedError.dataThis is extracted from the error.data property. If this property is not a plain object, then it will default to an empty object: {}.
Consult the Migration Guide if you're trying to migrate to a later major version of this package.
See the central contributing guide for Reliability Kit.
Licensed under the MIT license.
Copyright © 2022, The Financial Times Ltd.
FAQs
A utility function to serialize an error object in a way that's friendly to loggers, view engines, and converting to JSON
The npm package @dotcom-reliability-kit/serialize-error receives a total of 4,422 weekly downloads. As such, @dotcom-reliability-kit/serialize-error popularity was classified as popular.
We found that @dotcom-reliability-kit/serialize-error demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.