
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
error-to-json
Advanced tools
Returns a JSON representation of an error (handles nested errors and calls nested toJSONs)
Returns a JSON representation of an error (handles nested errors and calls nested toJSONs)
npm i --save error-to-json
// esm
import errorToJSON from 'error-to-json'
// commonjs
const errorToJSON = require('error-to-json')
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)
/*
{
"name": "Error",
"message": "boom",
"stack": "Error: boom\n ....",
"data": {
"err": { // nested error was also converted to json
"name": "TypeError",
"message": "boom2",
"stack": "TypeError: boom2\n ...."
},
"model": { // toJSON was called!
"x": 1,
"y": 2
}
}
}
*/
import { parse } from 'error-to-json'
var err = parse({
message: 'boom2',
stack: 'Error: boom2\n at ...\n at...',
})
/*
> err
[ Error: boom2 ]
> err.stack
`Error: boom2
at ...
at ...`
*/
var err2 = parse({
message: 'boom',
// no stack
})
/*
> err2
[ Error: boom ]
> err2.stack
'Error: boom'
*/
#License MIT
FAQs
Returns a JSON representation of an error (handles nested errors and calls nested toJSONs)
We found that error-to-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.