https://github.com/dadi/format-error
Create JSON error objects for DADI applications
https://github.com/dadi/format-error
Last synced: about 1 year ago
JSON representation
Create JSON error objects for DADI applications
- Host: GitHub
- URL: https://github.com/dadi/format-error
- Owner: dadi
- Created: 2016-10-03T07:01:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-03T15:00:04.000Z (about 7 years ago)
- Last Synced: 2024-04-25T23:22:35.889Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 119 KB
- Stars: 2
- Watchers: 13
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DADI Error Formatter
> Create JSON error objects for DADI applications
[](https://www.npmjs.com/package/@dadi/format-error)
[](https://coveralls.io/github/dadi/format-error?branch=master)
[](http://standardjs.com/)
## Overview
format-error is designed to streamline the process of creating errors to be returned from a DADI product.
## Install
```
npm install @dadi/format-error
```
## Usage
### createApiError(code, params)
```js
const formatError = require('@dadi/format-error')
let error = formatError.createApiError('0001', { field: 'publicationDate' })
```
```json
{
"code": "API-0001",
"title": "Missing Index Key",
"details": "'publicationDate' is specified as the primary sort field, but is missing from the index key collection.",
"docLink": "http://docs.dadi.tech/errors/api/API-0001"
}
```
### createError(product, code, params, codes)
```js
const formatError = require('@dadi/format-error')
const codes = {
"0001": {
"code": "API-0001",
"title": "Missing Index Key",
"details": "'${field}' is specified as the primary sort field, but is missing from the index key collection.",
"params": ["field"]
},
"0002": {
"code": "API-0002",
"title": "Hook Error",
"details": "${hookName} - ${errorMessage}",
"params": ["hookName", "errorMessage"]
}
}
let error = formatError.createError('api', '0001', { field: 'publicationDate' }, codes)
```