@onekeyfe/blockchain-link
Version:
High-level javascript interface for blockchain communication
59 lines (58 loc) • 2.32 kB
JavaScript
;
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) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomError = void 0;
var PREFIX = 'blockchain_link/';
var ERROR = {
worker_not_found: 'Worker not found',
worker_invalid: 'Invalid worker object',
worker_timeout: 'Worker timeout',
worker_unknown_request: 'Unknown message type:',
worker_runtime: undefined,
invalid_param: 'Invalid parameter:',
websocket_not_initialized: 'WebSocket not initialized',
websocket_no_url: 'Cannot connect because no server was specified',
websocket_timeout: 'Websocket timeout',
websocket_error_message: undefined,
websocket_runtime_error: undefined,
};
var CustomError = (function (_super) {
__extends(CustomError, _super);
function CustomError(code, message) {
if (message === void 0) { message = ''; }
var _this = _super.call(this, message) || this;
_this.message = '';
_this.message = message;
if (typeof code === 'string') {
var c = code.indexOf(PREFIX) === 0 ? code.substring(PREFIX.length, code.length) : code;
_this.code = "" + PREFIX + c;
var msg = ERROR[c];
if (typeof msg === 'string') {
if (_this.message === '') {
_this.message = msg;
}
else if (message.indexOf('+') === 0) {
_this.message = msg + " " + message.substr(1, message.length);
}
}
}
if (typeof _this.message !== 'string' || _this.message === '') {
_this.message = 'Message not set';
}
return _this;
}
return CustomError;
}(Error));
exports.CustomError = CustomError;