Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dotcom-reliability-kit/errors

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotcom-reliability-kit/errors - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

lib/data-store-error.js

5

lib/index.js

@@ -6,4 +6,7 @@ /**

module.exports = {
DataStoreError: require('./data-store-error'),
HttpError: require('./http-error'),
OperationalError: require('./operational-error')
OperationalError: require('./operational-error'),
UpstreamServiceError: require('./upstream-service-error'),
UserInputError: require('./user-input-error')
};

2

package.json
{
"name": "@dotcom-reliability-kit/errors",
"version": "1.1.2",
"version": "1.2.0",
"description": "A suite of error classes which help you throw the most appropriate error in any situation",

@@ -5,0 +5,0 @@ "repository": {

@@ -13,2 +13,5 @@

* [Why use this over `http-errors`?](#why-use-this-over-http-errors)
* [`DataStoreError`](#datastoreerror)
* [`UpstreamServiceError`](#upstreamserviceerror)
* [`UserInputError`](#userinputerror)
* [Contributing](#contributing)

@@ -42,4 +45,6 @@ * [License](#license)

It works in the same way as a normal error, expecting a message:
It's always best to use a more specific error, e.g. [`UpstreamServiceError`](#upstreamserviceerror), if one exists that suits your needs. So review the docs here to find the most suitable error.
`OperationalError` can work in the same way as a normal error, expecting a message:
```js

@@ -137,3 +142,55 @@ throw new OperationalError('example message');

### `DataStoreError`
The `DataStoreError` class extends `OperationalError` and represents an error which occurred while accessing a data store, e.g. MongoDB, PostgreSQL, or Redis. It has all of the features of operational errors, you can construct with just a message:
```js
throw new DataStoreError('Could not connect to Redis');
```
You can alternatively construct a data store error with a data object. You can use any of the properties defined in [`OperationalError`](#operationalerror):
```js
throw new DataStoreError({
code: 'REDIS_CONNECTION_FAILED',
message: 'Could not connect to Redis',
});
```
### `UpstreamServiceError`
The `UpstreamServiceError` class extends `HttpError` and represents an error which occurred while connecting to an upstream service, e.g. an FT or third-party API. It has all of the features of operational and HTTP errors, you can construct with just a message:
```js
throw new UpstreamServiceError('Content could not be fetched');
```
You can alternatively construct an upstream service error with a data object. You can use any of the properties defined in [`HttpError`](#httperror) and [`OperationalError`](#operationalerror):
```js
throw new UpstreamServiceError({
code: 'CONTENT_PIPELINE_FAILED',
message: 'Content could not be fetched, the content pipeline is responding with a 503 status',
statusCode: 503,
relatesToSystems: ['cp-content-pipeline-graphql']
});
```
### `UserInputError`
The `UserInputError` class extends `HttpError` and represents an error which occurred based on invalid user input, e.g. they inputted a malformed email address into a form. It has all of the features of operational and HTTP errors but defaults to a `400` status code. You can construct with just a message:
```js
throw new UserInputError('An invalid email address was input');
```
You can alternatively construct a user input error with a data object. You can use any of the properties defined in [`HttpError`](#httperror) and [`OperationalError`](#operationalerror):
```js
throw new UserInputError({
code: 'REGISTRATION_INFO_INVALID',
message: 'An invalid email address was input'
});
```
## Contributing

@@ -140,0 +197,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc