"use strict";

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

var _serializeError = _interopRequireDefault(require("serialize-error"));

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

/**
 * Seralize error object and construct error message that shows all
 * error information
 * @param {object} error Node error object
 * @returns {string} error message
 */
function getFullErrorMessage(error) {
  const _error = (0, _serializeError.default)(error);

  let str = '';
  const {
    name,
    code,
    message,
    stack
  } = _error;
  if (name) str += `${name.toUpperCase()}: `;
  if (message) str += `${message}\n`;
  if (code) str += `CODE: ${code}\n`;
  if (stack) str += `STACK: ${stack}`;
  return str || JSON.stringify(error, null, 4) || error;
}