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AEA,mBAAO,CAAc,GACjB,OAAO,qBAAqB,EAChC,CAEA,0BAAO,CAAqB,GACxB,OAAO,aAAe,WACf,EAAI,OAAS,MAAQ,UAAU,aAAa,EAAI,UAAU,QAAQ,sBAAuB,IACpG,CAEA,MAAA,GACI,MAAO,CAAC,IAAK,KAAK,OAAQ,UAAW,KAAK,UAAW,OAAQ,KAAK,QACtE,EAGJ,IAAI,QAAU,SAAU,EAAS,GAC7B,IAAI,EAAS,CAAC,EAgCd,OA/BA,EAAE,KAAK,GAAS,SAAU,EAAQ,IAC9B,EAAS,EAAE,QAAQ,GAAU,CAAC,SAAU,GAAU,GAE3C,SAAW,EAAO,SAAS,KAAI,IAClC,GAAI,EAAW,SAAW,EAAW,QAAQ,QAAU,EAAW,QAAQ,KAAM,CAC5E,IAAI,OAAC,EAAM,KAAE,GAAQ,EAAW,QAChC,EAAW,QAAU,SAAU,GAC3B,IAEI,EAFA,EAAU,eACd,EAAQ,UAAY,EAEpB,IAAI,EAAM,EACV,KAAyC,QAAjC,EAAS,EAAQ,KAAK,MAAoB,EAAE,YAAY,IAAW,EAAM,IAC7E,EAAO,EAAK,QAAQ,cAAe,EAAK,EAAO,KAC/C,IAEJ,OAAO,CACX,CACJ,CAEA,OAAO,CAAU,IAGrB,IAAI,EAAW,UAAU,uBAAuB,EAAc,EAAa,IAAO,IAAM,EAAM,EAAO,UAChG,IACD,EAAO,GAAQ,GAEnB,EAAO,UAAY,EAAE,KAAK,EAAO,UAAU,SAAU,EAAO,GACxD,QAAQ,CAAC,CAAC,GAAM,GAAQ,EAC5B,GACJ,IAEO,CACX,EAEA,OAAO,QAAU,CACb,SAAU,UACV","file":"/npm/dora-error@0.0.1/error.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/dora-error@0.0.1/error.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\r\n * Created on 2016/5/24.\r\n * @fileoverview 请填写简要的文件说明.\r\n * @author joc (Firstname Lastname)\r\n */\r\nconst _ = require('lodash');\r\n\r\nlet errorTypes = [], errorMap = {}, errCodeMap = {};\r\nlet STEP = 10000, SUB_STEP = 100,\r\n    NAMING_RULE = /[A-Z]\\w+/,\r\n    SUB_NAMING_RULE = /[A-Z]\\w+(\\.[A-Z]\\w+)+/,\r\n    checkErrType = function (errorType, isSubType) {\r\n        if (errorTypes.indexOf(errorType) >= 0) {\r\n            throw new Error('duplicate errorType \"' + errorType + '\".');\r\n        }\r\n        if (!(isSubType ? SUB_NAMING_RULE : NAMING_RULE).test(errorType)) {\r\n            throw new Error(`errorType ${errorType} is not UpperCamelCase style.`);\r\n        }\r\n    },\r\n    registerErrSpace = function (ctx, currentSpace, errorType) {\r\n        errorTypes.push(errorType);\r\n        ctx._currentSpace = ctx.errorSpace = ctx.errorCode = currentSpace;\r\n        ctx.errorType = errorType;\r\n        errCodeMap[currentSpace] = errorMap[errorType] = ctx;\r\n    },\r\n    isErrTypeIns;\r\nlet currentSpace = STEP;\r\n\r\nclass _SubErrorType {\r\n    constructor (parent, errorType) {\r\n        errorType = [parent.errorType, errorType].join('.');\r\n        checkErrType(errorType, true);\r\n\r\n        parent._currentSpace += SUB_STEP;\r\n        registerErrSpace(this, parent._currentSpace, errorType);\r\n    }\r\n}\r\n\r\nclass ErrorType {\r\n    constructor (errorType) {\r\n        checkErrType(errorType);\r\n\r\n        registerErrSpace(this, currentSpace, errorType);\r\n        currentSpace += STEP;\r\n    }\r\n    SubErrorTypeFactory (errorType) {\r\n        return new _SubErrorType(this, errorType);\r\n    }\r\n}\r\n\r\nisErrTypeIns = function (ins) {\r\n    return ins instanceof ErrorType;\r\n};\r\n\r\n[_SubErrorType, ErrorType].forEach(function (clazz) {\r\n    _.extend(clazz.prototype, {\r\n        getErrorMsg (errKey) {\r\n            let isName = _.isString(errKey);\r\n            return this[isName ? '_spaceConfigs' : '_spaceIndexes'][errKey];\r\n        },\r\n\r\n        configErrorSpace (messages) {\r\n            let self = this;\r\n            if (messages.length > SUB_STEP) {\r\n                throw new Error('expect an array with length not greater than ' + SUB_STEP);\r\n            }\r\n\r\n            let configs = self._spaceConfigs = {};\r\n            let indexes = self._spaceIndexes = [];\r\n\r\n            messages.forEach(function (msg) {\r\n                let {index, name} = msg;\r\n                if (configs[name] || indexes[index]) {\r\n                    throw new Error(`duplicate ${configs[name] ? 'name' : 'index'} on ${self.errorType}.${name}`);\r\n                }\r\n                if (index < 0 || index >= SUB_STEP) {\r\n                    throw new Error(`${self.errorType}.${name} has an index out of range (0~${SUB_STEP - 1}).`);\r\n                }\r\n                indexes[index] = configs[name] = msg;\r\n            });\r\n        }\r\n    });\r\n});\r\n\r\nlet getErrorTypeInstance = function (errorType) {\r\n    let errTypeIsString = _.isString(errorType);\r\n    if (!errTypeIsString && !isErrTypeIns(errorType)) {\r\n        throw new Error('errorType must be string type or ErrorType instance.');\r\n    }\r\n\r\n    if (errTypeIsString) {\r\n        let _errorType = errorMap[errorType];\r\n        if (!_errorType) {\r\n            throw new Error('errorType \"' +\r\n                            errorType +\r\n                            '\" is not registered. If you want a sub ErrorType instance, ' +\r\n                            'you should pass the errorType as \"Parent.Son\" format.');\r\n        }\r\n        errorType = _errorType;\r\n    }\r\n    return errorType;\r\n};\r\n\r\n/**\r\n * 应用级别的异常处理类\r\n */\r\nclass DoraError extends Error {\r\n    /**\r\n     * @constructor\r\n     * @param errorCode {!number}\r\n     * @param errorType {!String}\r\n     * @param reason {?string=}\r\n     * @param details {?object=}\r\n     */\r\n    constructor (errorCode, errorType, reason, details) {\r\n        super(errorType, reason, details);\r\n\r\n        if (!details && !_.isString(reason)) {\r\n            [reason, details] = [null, reason];\r\n        }\r\n        let self = this;\r\n        // Ensure we get a proper stack trace in most Javascript environments\r\n        if (Error.captureStackTrace) {\r\n            // V8 environments (Chrome and Node.js)\r\n            Error.captureStackTrace(self, DoraError);\r\n        } else {\r\n            // Borrow the .stack property of a native Error object.\r\n            self.stack = new Error().stack;\r\n        }\r\n        self.errorType = errorType;\r\n        self.reason = reason;\r\n        self.error = errorCode;\r\n        self.details = self.details || details;\r\n\r\n        if (self.reason) {\r\n            self.message = self.reason + ' [' + self.error + ']';\r\n        } else {\r\n            self.message = '[' + self.error + ']';\r\n        }\r\n    }\r\n\r\n    static configs (config) {\r\n        if (!config) {\r\n            return {\r\n                STEP,\r\n                SUB_STEP,\r\n                NAMING_RULE,\r\n                SUB_NAMING_RULE\r\n            };\r\n        }\r\n\r\n        STEP = config.STEP || STEP;\r\n        SUB_STEP = config.SUB_STEP || SUB_STEP;\r\n        NAMING_RULE = config.NAMING_RULE || NAMING_RULE;\r\n        SUB_NAMING_RULE = config.SUB_NAMING_RULE || SUB_NAMING_RULE;\r\n    }\r\n\r\n    static DoraErrorClassFactory (errorType, messages) {\r\n        let isSubType = /\\./.test(errorType);\r\n        let relations = isSubType && errorType.match(/^(\\w+)\\.([\\w\\.]+)/).slice(1);\r\n        let errTypeIns = isSubType ?\r\n                         DoraError.SubErrorTypeFactory(...relations) :\r\n                         DoraError.ErrorTypeFactory(errorType);\r\n\r\n        errorType = errTypeIns.errorType;\r\n        messages && errTypeIns.configErrorSpace(messages);\r\n\r\n        let fac = function (errorType, reason, details) {\r\n            if (!details && !_.isString(reason)) {\r\n                [reason, details] = [null, reason];\r\n            }\r\n\r\n            let self = {};\r\n            let {errKey} = errorType;\r\n\r\n            if (errKey >= SUB_STEP || errKey < 0) {\r\n                throw new TypeError('offset cannot less greater than or equal to' + SUB_STEP + ', or less than 0.');\r\n            }\r\n            self.errorType = errorType.errorType;\r\n            self.reason = errorType.getErrorMsg(errKey);\r\n            if (_.isObject(self.reason)) {\r\n                errKey = self.reason.index;\r\n                self.errorType += '.' + self.reason.name;\r\n                self.reason = self.reason.message;\r\n                if (_.isFunction(self.reason)) {\r\n                    self.reason = self.reason(details && details.msgParams);\r\n                }\r\n            }\r\n            self.reason = reason || self.reason;\r\n            if (_.isString(errKey)) {\r\n                throw new Error(`error key ${errKey} is not defined.`);\r\n            }\r\n            self.error = errorType.errorCode + errKey;\r\n            if (details) {\r\n                self.details = _.isObject(details) ? _.omit(details, 'msgParams') : details;\r\n            }\r\n\r\n            return self;\r\n        };\r\n\r\n        class Err extends DoraError {\r\n            constructor (errKey, reason, details) {\r\n                let proto = fac(_.extend(errTypeIns, {errKey: errKey = errKey || 0}), reason, details);\r\n                super(proto.error, proto.errorType, proto.reason, proto.details);\r\n            }\r\n        }\r\n        let ins = DoraError;\r\n        relations = relations || [errorType];\r\n        relations.slice(0, -1).forEach(function (errType) {\r\n            ins = ins[errType];\r\n        });\r\n        return ins[relations[relations.length - 1]] = Err;\r\n    }\r\n\r\n    static ErrorTypeFactory (name) {\r\n        return new ErrorType(name);\r\n    }\r\n\r\n    static SubErrorTypeFactory (parent, name) {\r\n        parent = getErrorTypeInstance(parent);\r\n        return parent[name.replace(parent.errorType + '.', '')] = parent.SubErrorTypeFactory(name);\r\n    }\r\n\r\n    static getErrorType (name) {\r\n        return getErrorTypeInstance(name);\r\n    }\r\n\r\n    static isDoraErrorInstance (ins) {\r\n        return ins instanceof DoraError ||\r\n               ins.error >= STEP && DoraError.getErrorType(ins.errorType.replace(/(\\.[_a-z][\\w\\-]+)+$/, ''));\r\n    }\r\n\r\n    toJSON () {\r\n        return {msg: this.reason, errorType: this.errorType, detail: this.details};\r\n    }\r\n}\r\n\r\nlet factory = function (configs, parentName) {\r\n    let errMap = {};\r\n    _.each(configs, function (config, name) {\r\n        config = _.isArray(config) ? {messages: config} : config;\r\n\r\n        config.messages = config.messages.map(messageObj => {\r\n            if (messageObj.message && messageObj.message.params && messageObj.message.func) {\r\n                let {params, func} = messageObj.message;\r\n                messageObj.message = function (args) {\r\n                    let pattern = /\\$\\{(\\d+)\\}/g;\r\n                    pattern.lastIndex = 0;\r\n                    let result;\r\n                    let idx = 0;\r\n                    while ((result = pattern.exec(func)) !== null && (_.isUndefined(params) || idx < params)) {\r\n                        func = func.replace(/\\$\\{(\\d+)\\}/, args[result[1]]);\r\n                        idx++;\r\n                    }\r\n                    return func;\r\n                };\r\n            }\r\n\r\n            return messageObj;\r\n        });\r\n\r\n        let ErrClass = DoraError.DoraErrorClassFactory((parentName ? (parentName + '.') : '') + name, config.messages);\r\n        if (!parentName) {\r\n            errMap[name] = ErrClass;\r\n        }\r\n        config.children && _.each(config.children, function (child, key) {\r\n            factory({[key]: child}, name);\r\n        });\r\n    });\r\n\r\n    return errMap;\r\n};\r\n\r\nmodule.exports = {\r\n    ErrClass: DoraError,\r\n    factory\r\n};\r\n"]}