function errorToJSON () {
var json = {};

// Get all the properties of this error
var keys = Object.keys(this);

// Also include properties from the Error prototype
keys = keys.concat(errorPrototypeProperties);

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  var value = this[key];
  var type = typeof value;
  if (type !== 'undefined' && type !== 'function') {
    json[key] = value;
  }
}

return json;
}
Custom JSON serializer for Error objects.
Returns all built-in error properties, as well as extended properties.

@returns {object}