@dotcom-reliability-kit/errors
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -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') | ||
}; |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18634
8
368
202