Augment errors with `Error#toJSON` that preserves `name`, `message`, `stack` as well as any other normally stringified attribute.
npm install error-stringifyAugment errors with Error#toJSON that preserves name, message, stack as well as any other
normally stringified attribute.
log.warn("error %j", error)module.exportThe usage vary between the following two extremes.
Pass what you need to control the behavior :)
``js`
require('error-stringify')()
Default behavior does not split stack traces, and includes only properties on the passed
instance (enumerable or not).
- provide target through the options.target parameter, or by the targetsplitStackTrace
- explicit switches
- - booleanincludeProtoChain
- - boolean
`js
var AppError = require('./app-error-base');
require('error-stringify')({
target : AppError
splitStackTrace : true,
includeProtoChain : true
})
`
which is effectively the equivalent of:
`js
var AppError = require('./app-error-base');
var options = {
splitStackTrace : true,
includeProtoChain : true
};
require('error-stringify')(options, AppError)
`
The later form is useful when you want to pick the options from a file and pass it as is,
so you can pass the base Error constructor in the 2nd argument.
`js
require('error-stringify')({
allowOverrideToJSON : true
})
`
```
npm install error-stringify --save
Happy coding :)