format-error
Formats an error object such that:
- message is ignored; assumes it's in the stack
- full stack is displayed
- other properties on object are displayed
- nested errors are displayed
install
npm install --save format-error
example
var format = require('format-error').format;
var error = new Error('something broke');
error.inner = new Error('some inner thing broke');
error.code = '500c';
error.severity = 'high';
var message = format(error);
console.error(message);
api
format(error, prettyjsonOptions)
Formats an error for output.
error
is an Error object.
prettyjsonOptions
(optional) is passed directly to
prettyjson.
patchError()
Permanently patches the error object
such that serialization (toJSON
calls)
behave according to the goals
of this module.
This is not required
unless you want JSON.stringify(error)
to act somewhat like format(error)
in cases where you can't
control how the output is formatted directly.
This module only temporarily
patches Error in order to
produce the formatted output.
This can be undone by calling unpatchError()
.
unpatchError()
This reverts changes made to
Error.prototype.toJSON
by patchError()
.
This should only be called if
you explictly called patchError
.
License
MIT