UNPKG

@lgd-utils/error

Version:
61 lines (56 loc) 1.61 kB
import lodashForOwn from 'lodash/forOwn'; import lodashSet from 'lodash/set'; /* * @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 */ class ExtendableError extends Error { constructor(message) { super(message); this.name = this.constructor.name; if (typeof Error.captureStackTrace === 'function') { Error.captureStackTrace(this, this.constructor); } else { this.stack = new Error(message).stack; } } } /* * @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 */ class CustomError extends ExtendableError { constructor(message, payload) { super(message); this.isCustomError = true; lodashForOwn(payload, (value, key) => { lodashSet(this, key, value); }); } } 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, ExtendableError, }; export { CustomError, ExtendableError, error_default as default };