'use strict';

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

var _ui = require('../../common/actions/ui');

var _alerts = require('../../common/actions/alerts');

var _constants = require('../../constants');

var _formatMessage = require('../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var handleBankError = exports.handleBankError = function handleBankError(dispatch) {
  return function (error) {
    if ([404, 401].includes(error.response.status)) {
      // need a timeout so focus is not stolen by
      // other callbacks after the alert opens
      setTimeout(function () {
        dispatch((0, _ui.set)(_constants.TRAY_ALERT_OPEN, true));
      }, 500);
    } else {
      dispatch((0, _alerts.addError)('Beklager, det oppstod en ' + error.response.status + ' feil.'));
    }
  };
};