'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.systemFields = undefined;
exports.default = cloneErrorObject;

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var systemFields = exports.systemFields = ['stack', 'code', 'errno', 'syscall'];

// partially forked from 'utils-copy-error' package

function cloneErrorObject(error) {
  // $FlowFixMe
  var err = new error.constructor(error.message);

  systemFields.forEach(function (field) {
    // $FlowFixMe
    if (error[field]) err[field] = error[field];
  });
  Object.keys(error).forEach(function (key) {
    // $FlowFixMe
    err[key] = (_ramda || _load_ramda()).default.clone(error[key]);
  });
  return err;
}