@dotcom-reliability-kit/errors
A suite of error classes which help you throw the most appropriate error in any situation, and identify when errors are known vs unknown. This module is part of FT.com Reliability Kit.
Usage
Install @dotcom-reliability-kit/errors
as a dependency:
npm install --save @dotcom-reliability-kit/errors
Include in your code:
import {OperationalError} from '@dotcom-reliability-kit/errors';
const {OperationalError} = require('@dotcom-reliability-kit/errors');
This module exports different Error classes which have different jobs. All can be imported in the same way as the example above.
OperationalError
The OperationalError
class is the base class for most other error types. "Operational" in this context means "we understand why this error has occurred", so by using this error type you're helping your team to understand when a thrown error is unexpected.
It works in the same way as a normal error, expecting a message:
throw new OperationalError('example message');
OperationalError.isErrorMarkedAsOperational()
You can test whether an error is operational (known about) either by using the isErrorMarkedAsOperational
method. It accepts an error object of any kind and will return true
if that error has a truthy isOperational
property and false
otherwise:
OperationalError.isErrorMarkedAsOperational(new OperationalError('example message'));
OperationalError.isErrorMarkedAsOperational(new Error('example message'));
Contributing
See the central contributing guide for Reliability Kit.
License
Licensed under the MIT license.
Copyright © 2022, The Financial Times Ltd.