error-to-json
Returns a JSON representation of an error (handles nested errors and calls nested toJSONs)
Installation
npm i --save error-to-json
Usage
Supports both ESM and CommonJS
import errorToJSON from 'error-to-json'
const errorToJSON = require('error-to-json')
Example: toJSON
import errorToJSON from 'error-to-json'
var model = {
_json: {
x: 1,
y: 2
}
helper: function () {},
toJSON: function () {
return this._json
}
}
var err = new Error('boom')
err.data = {
err: new TypeError('boom2'),
model: model
}
var json = errorToJSON(err)
Example: Parse
import { parse } from 'error-to-json'
var err = parse({
message: 'boom2',
stack: 'Error: boom2\n at ...\n at...',
})
var err2 = parse({
message: 'boom',
})
#License
MIT