'use strict';

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

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

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

const getMessage = error => {
  const message = (0, _get2.default)(error, 'message');
  const data = (0, _get2.default)(error, ['response', 'data']);

  const parts = [message, typeof data === 'string' ? data : null];

  return parts.filter(part => !!part).join(': ');
};

exports.default = error => {
  const errorMessage = getMessage(error);

  const internalError = error.error;
  const internalErrorMessage = internalError ? getMessage(internalError) : null;

  const parts = [errorMessage, internalErrorMessage];

  return parts.filter(part => !!part).join(': ');
};