New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

super-errors-json

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

super-errors-json

Convert a SuperError instance into JSON notation safe for clients.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

super-errors-json

Convert a SuperError instance into JSON that is safe for clients.

Example:


var Errors = require('super-errors')();
require('super-errors-json')(Errors);

var json = Errors.json(new Errors.NotifyUser('Test...'));

The json variable should now be a string that looks like:

{"name":"NotifyUser","message":"Test...","status_code":500}

SuperErrors.json(error, [json_obj], map, exclude)

  • error (Error): The error to serialize.
  • json_obj (boolean): Whether to return a JSON string (default) or return a JSON-serializable object (true)
  • map (Object): Map of fields to be included and how they are to be renamed
  • exclude (Object): Fields that should be excluded from the object

The map argument can be used to map where fields go and defaults to:

{
    "client_safe_message": 'message',
    "errors.client_safe_message": 'errors',
    "field": 'field',
    "fields.client_safe_message": 'fields',
    "name": 'name',
    "status_code": 'status_code'
}

This map will give you the name, field, status_code and client_safe_message of the error. All additional errors get converted to strings and placed in an array and fields become an object of fields.

The exclude argument can be used to mark fields you don't want included in resulting object.

Keywords

SuperErrors

FAQs

Package last updated on 12 Jan 2017

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