json-api-errors
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "json-api-errors", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "JSON api errors formatter", | ||
@@ -5,0 +5,0 @@ "main": "errors.js", |
108
README.md
@@ -1,2 +0,106 @@ | ||
JSON API Errors | ||
=============== | ||
# JSON API Errors | ||
Create errors using [JSON API errors format](http://jsonapi.org/format/#errors) | ||
[![npm package](https://nodei.co/npm/json-api-errors.png?downloads=true&downloadRank=true&stars=true)][package] | ||
[![version](https://img.shields.io/npm/v/json-api-errors.svg?style=flat-square)][version] | ||
[![build](https://img.shields.io/travis/theworkflow/json-api-errors/master.svg?style=flat-square)][build] | ||
[![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license] | ||
[![climate](https://img.shields.io/codeclimate/github/theworkflow/json-api-errors.svg?style=flat-square)][climate] | ||
[![coverage](https://img.shields.io/codeclimate/coverage/github/theworkflow/json-api-errors.svg?style=flat-square)][coverage] | ||
### Installation | ||
`$ npm install json-api-errors` | ||
### Usage | ||
#### `Errors.createSingle(id, message, [meta])` | ||
Create a single errors object. | ||
- `id` (String) | ||
- required | ||
- `message` (String) | ||
- required | ||
- `meta` (Object | String) | ||
- optional | ||
```javascript | ||
const Errors = require('json-api-errors') | ||
var errors = new Errors() | ||
var err = errors.createSingle('CUSTOM_ERROR', 'Custom error message') | ||
console.log(err) | ||
// { | ||
// errors: [{ id: 'CUSTOM_ERROR', message: 'Custom error message' }] | ||
// } | ||
``` | ||
#### `Errors.add(id, message, [meta])` | ||
Add an error to the errors array | ||
- `id` (String) | ||
- required | ||
- `message` (String) | ||
- required | ||
- `meta` (Object | String) | ||
- optional | ||
```javascript | ||
const Errors = require('json-api-errors') | ||
var errors = new Errors() | ||
errors.add('CUSTOM_ERROR', 'Custom error message') | ||
``` | ||
#### `Errors.get()` | ||
Retreive all errors. Errors are returned in a JSON format | ||
```javascript | ||
const Errors = require('json-api-errors') | ||
var errors = new Errors() | ||
errors.add('CUSTOM_ERROR', 'Custom error message') | ||
var errs = errors.get() | ||
// { | ||
// errors: [{ id: 'CUSTOM_ERROR', message: 'Custom error message' }] | ||
// } | ||
``` | ||
#### `Errors.clear()` | ||
Remove all errors | ||
```javascript | ||
const Errors = require('json-api-errors') | ||
var errList, errors = new Errors() | ||
errors.add('CUSTOM_ERROR', 'Custom error message') | ||
errList = errors.get() | ||
console.log(errList.errors) // Length is 1 | ||
errors.clear() | ||
errList = errors.get() | ||
console.log(errList.errors) // Length is 0 | ||
``` | ||
### Tests | ||
`$ npm test` | ||
[package]: https://nodei.co/npm/json-api-errors | ||
[version]: https://www.npmjs.com/package/json-api-errors | ||
[build]: https://travis-ci.org/theworkflow/api-util | ||
[license]: https://raw.githubusercontent.com/theworkflow/json-api-errors/master/LICENSE | ||
[climate]: https://codeclimate.com/github/theworkflow/json-api-errors | ||
[coverage]: https://codeclimate.com/github/theworkflow/json-api-errors/coverage |
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
9277
11
106