"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

function _ramda() {
  const data = _interopRequireDefault(require("ramda"));

  _ramda = function () {
    return data;
  };

  return data;
}

const systemFields = ['stack', 'code', 'errno', 'syscall']; // partially forked from 'utils-copy-error' package

exports.systemFields = systemFields;

function cloneErrorObject(error) {
  // $FlowFixMe
  const err = new error.constructor(error.message);
  systemFields.forEach(field => {
    // $FlowFixMe
    if (error[field]) err[field] = error[field];
  });
  Object.keys(error).forEach(key => {
    // $FlowFixMe
    err[key] = _ramda().default.clone(error[key]);
  });
  return err;
}