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

json-api-errors

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-api-errors - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

LICENSE

2

package.json
{
"name": "json-api-errors",
"version": "0.1.0",
"version": "0.2.0",
"description": "JSON api errors formatter",

@@ -5,0 +5,0 @@ "main": "errors.js",

@@ -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
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