"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NotAuthenticatedError = exports.UnsupportedError = exports.NotFoundError = exports.ForbiddenError = exports.ServerError = exports.InvalidArgumentError = exports.ConnectorError = void 0;

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }

function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }

function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

/**
 * The `errors` module contains any error type classes used by
 * Commerce Integrations.
 * @module @mobify/commerce-integrations/dist/errors
 */
var ConnectorError =
/*#__PURE__*/
function (_Error) {
  _inherits(ConnectorError, _Error);

  function ConnectorError(statusCode, message) {
    var _this;

    _classCallCheck(this, ConnectorError);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(ConnectorError).call(this, message));
    _this.constructor = ConnectorError;
    _this.__proto__ = ConnectorError.prototype;
    _this.message = message;
    _this.statusCode = statusCode;
    return _this;
  }

  _createClass(ConnectorError, [{
    key: "toString",
    value: function toString() {
      return "ConnectorError ".concat(this.statusCode, ": ").concat(this.message);
    }
  }]);

  return ConnectorError;
}(_wrapNativeSuper(Error));
/**
 * The user supplied invalid arguments to a function/method.
 * Usually an error in code.
 */


exports.ConnectorError = ConnectorError;

var InvalidArgumentError =
/*#__PURE__*/
function (_ConnectorError) {
  _inherits(InvalidArgumentError, _ConnectorError);

  function InvalidArgumentError(msg) {
    var _this2;

    _classCallCheck(this, InvalidArgumentError);

    _this2 = _possibleConstructorReturn(this, _getPrototypeOf(InvalidArgumentError).call(this, 400, msg));
    _this2.constructor = InvalidArgumentError;
    _this2.__proto__ = InvalidArgumentError.prototype;
    return _this2;
  }

  return InvalidArgumentError;
}(ConnectorError);
/**
 * The server returned an error response.
 */


exports.InvalidArgumentError = InvalidArgumentError;

var ServerError =
/*#__PURE__*/
function (_ConnectorError2) {
  _inherits(ServerError, _ConnectorError2);

  function ServerError(msg) {
    var _this3;

    _classCallCheck(this, ServerError);

    _this3 = _possibleConstructorReturn(this, _getPrototypeOf(ServerError).call(this, 500, msg));
    _this3.constructor = ServerError;
    _this3.__proto__ = ServerError.prototype;
    return _this3;
  }

  return ServerError;
}(ConnectorError);
/**
 * The server returned a forbidden response.
 */


exports.ServerError = ServerError;

var ForbiddenError =
/*#__PURE__*/
function (_ConnectorError3) {
  _inherits(ForbiddenError, _ConnectorError3);

  function ForbiddenError(msg) {
    var _this4;

    _classCallCheck(this, ForbiddenError);

    _this4 = _possibleConstructorReturn(this, _getPrototypeOf(ForbiddenError).call(this, 403, msg));
    _this4.constructor = ForbiddenError;
    _this4.__proto__ = ForbiddenError.prototype;
    return _this4;
  }

  return ForbiddenError;
}(ConnectorError);
/**
 * The server returned a not found response.
 */


exports.ForbiddenError = ForbiddenError;

var NotFoundError =
/*#__PURE__*/
function (_ConnectorError4) {
  _inherits(NotFoundError, _ConnectorError4);

  function NotFoundError(msg) {
    var _this5;

    _classCallCheck(this, NotFoundError);

    _this5 = _possibleConstructorReturn(this, _getPrototypeOf(NotFoundError).call(this, 404, msg));
    _this5.constructor = NotFoundError;
    _this5.__proto__ = NotFoundError.prototype;
    return _this5;
  }

  return NotFoundError;
}(ConnectorError);
/**
 * The called method is not implemented or supported on a backend.
 */


exports.NotFoundError = NotFoundError;

var UnsupportedError =
/*#__PURE__*/
function (_ConnectorError5) {
  _inherits(UnsupportedError, _ConnectorError5);

  function UnsupportedError(msg) {
    var _this6;

    _classCallCheck(this, UnsupportedError);

    _this6 = _possibleConstructorReturn(this, _getPrototypeOf(UnsupportedError).call(this, 500, msg));
    _this6.constructor = UnsupportedError;
    _this6.__proto__ = UnsupportedError.prototype;
    return _this6;
  }

  return UnsupportedError;
}(ConnectorError);
/**
 * A request was rejected because the user is not authenticated.
 *
 * In screen-scraping APIs this may be different from a "Forbidden"
 * response - eg. a redirect to a login page might trigger the error.
 */


exports.UnsupportedError = UnsupportedError;

var NotAuthenticatedError =
/*#__PURE__*/
function (_ConnectorError6) {
  _inherits(NotAuthenticatedError, _ConnectorError6);

  function NotAuthenticatedError(msg) {
    var _this7;

    _classCallCheck(this, NotAuthenticatedError);

    _this7 = _possibleConstructorReturn(this, _getPrototypeOf(NotAuthenticatedError).call(this, 401, msg));
    _this7.constructor = NotAuthenticatedError;
    _this7.__proto__ = NotAuthenticatedError.prototype;
    return _this7;
  }

  return NotAuthenticatedError;
}(ConnectorError);

exports.NotAuthenticatedError = NotAuthenticatedError;