UNPKG

@cloudbase/js-sdk

Version:
85 lines (84 loc) 3.02 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { isString } from './type'; import { ERR_CODE } from '../config/error.config'; var CloudSDKError = (function (_super) { __extends(CloudSDKError, _super); function CloudSDKError(options) { var _this = _super.call(this, options.errMsg) || this; _this.errCode = 'UNKNOWN_ERROR'; Object.defineProperties(_this, { message: { get: function () { return ("errCode: ".concat(this.errCode, " ").concat(ERR_CODE[this.errCode] || '', " | errMsg: ") + this.errMsg); }, set: function (msg) { this.errMsg = msg; } } }); _this.errCode = options.errCode || 'UNKNOWN_ERROR'; _this.errMsg = options.errMsg; return _this; } Object.defineProperty(CloudSDKError.prototype, "message", { get: function () { return "errCode: ".concat(this.errCode, " | errMsg: ") + this.errMsg; }, set: function (msg) { this.errMsg = msg; }, enumerable: false, configurable: true }); return CloudSDKError; }(Error)); export { CloudSDKError }; export function isSDKError(error) { return (error && error instanceof Error && isString(error.errMsg)); } export var isGenericError = function (e) { return e.generic; }; var TimeoutError = (function (_super) { __extends(TimeoutError, _super); function TimeoutError(message) { var _this = _super.call(this, message) || this; _this.type = 'timeout'; _this.payload = null; _this.generic = true; return _this; } return TimeoutError; }(Error)); export { TimeoutError }; export var isTimeoutError = function (e) { return e.type === 'timeout'; }; var CancelledError = (function (_super) { __extends(CancelledError, _super); function CancelledError(message) { var _this = _super.call(this, message) || this; _this.type = 'cancelled'; _this.payload = null; _this.generic = true; return _this; } return CancelledError; }(Error)); export { CancelledError }; export var isCancelledError = function (e) { return e.type === 'cancelled'; };