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

JSON api errors formatter

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

JSON API Errors

Create errors using JSON API errors format

npm package

version build license climate 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
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
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

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

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

Keywords

FAQs

Package last updated on 12 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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