UNPKG

@lgd-utils/error

Version:
127 lines (90 loc) 6.37 kB
'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } 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 _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 _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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } 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); } function _typeof(obj) { "@babel/helpers - typeof"; 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); } Object.defineProperty(exports, '__esModule', { value: true }); var lodashForOwn = require('lodash/forOwn'); var lodashSet = require('lodash/set'); function _interopDefaultLegacy(e) { return e && _typeof(e) === 'object' && 'default' in e ? e['default'] : e; } var lodashForOwn__default = /*#__PURE__*/_interopDefaultLegacy(lodashForOwn); var lodashSet__default = /*#__PURE__*/_interopDefaultLegacy(lodashSet); /* * @Author: shiconghua * @Alias: LGD.HuaFEEng * @Date: 2021-09-18 11:04:13 * @LastEditTime: 2021-09-18 11:06:03 * @LastEditors: shiconghua * @Description: file content * @FilePath: \lgd-utils\packages\error\src\ExtendableError.ts */ var ExtendableError = /*#__PURE__*/function (_Error) { _inherits(ExtendableError, _Error); var _super = _createSuper(ExtendableError); function ExtendableError(message) { var _this; _classCallCheck(this, ExtendableError); _this = _super.call(this, message); _this.name = _this.constructor.name; if (typeof Error.captureStackTrace === 'function') { Error.captureStackTrace(_assertThisInitialized(_this), _this.constructor); } else { _this.stack = new Error(message).stack; } return _this; } return ExtendableError; }( /*#__PURE__*/_wrapNativeSuper(Error)); /* * @Author: shiconghua * @Alias: LGD.HuaFEEng * @Date: 2021-09-18 11:08:31 * @LastEditTime: 2021-09-18 11:49:01 * @LastEditors: shiconghua * @Description: file content * @FilePath: \lgd-utils\packages\error\src\CustomError.ts */ var CustomError = /*#__PURE__*/function (_ExtendableError) { _inherits(CustomError, _ExtendableError); var _super2 = _createSuper(CustomError); function CustomError(message, payload) { var _this2; _classCallCheck(this, CustomError); _this2 = _super2.call(this, message); _this2.isCustomError = true; lodashForOwn__default(payload, function (value, key) { lodashSet__default(_assertThisInitialized(_this2), key, value); }); return _this2; } return CustomError; }(ExtendableError); CustomError.isCustomError = true; /* * @Author: shiconghua * @Alias: LGD.HuaFEEng * @Date: 2021-09-18 10:57:19 * @LastEditTime: 2021-09-18 11:27:59 * @LastEditors: shiconghua * @Description: file content * @FilePath: \lgd-utils\packages\error\src\error.default.ts */ var error_default = { CustomError: CustomError, ExtendableError: ExtendableError }; exports.CustomError = CustomError; exports.ExtendableError = ExtendableError; exports['default'] = error_default;