serrano
Javascript Error Serializer
Last updated 3 years ago by andy*() .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install serrano 
SYNC missed versions from official npm registry.

serrano

serialize error into POJO when you need to JSON.stringify() error

Examples

const serrano = require('serrano')

const error = new Error('error msg')

console.log(error)
//=> Error: error msg

console.log(JSON.stringify(error))
//=> {}

console.log(serrano(error))
//=> { message: 'error msg', stack: 'at Object.<anonymous> ...' }

error.err = error

try {
  console.log(JSON.stringify(error))
} catch (e) {
  console.error(e) // TypeError: Converting circular structure to JSON
}

console.log(serrano(error))
//=> { err: '[Circular]', message: 'error msg', stack: 'at Object.<anonymous> ...' }

error.child = new Error('child error msg')

console.log(serrano(error))
//=> { err: '[Circular]', message: 'error msg', stack: 'at Object.<anonymous> ...',
//=> child: { message: 'child error msg', stack: 'at Object.<anonymous> ...' } }

console.log(serrano(function test(x) {
  console.log('test', x)
}))
/*
function test(x) {
  console.log('test', x)
}
*/

Installation

npm install --save serrano

Usage

You can import from serrano:

const serrano = require('serrano');
// or
import serrano from 'serrano';

Current Tags

  • 0.1.0                                ...           latest (3 years ago)

1 Versions

  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |