serrano

0.1.0 • Public • Published

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';

Package Sidebar

Install

npm i serrano

Weekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

396 kB

Total Files

16

Last publish

Collaborators

  • andy*()