UNPKG

ethstats-cli

Version:
94 lines (81 loc) 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var Error = /*#__PURE__*/ function () { function Error(protocol) { _classCallCheck(this, Error); this.protocol = protocol; var _parityRecommendedFlags = { http: '`--jsonrpc-apis=web3,eth,net`', ws: '`--ws-apis=web3,eth,net,pubsub`', ipc: '`--ipc-apis=web3,eth,net,pubsub`' }; var _gethRecommendedFlags = { http: '`--rpc --rpcapi web3,eth,net`', ws: '`--ws --wsapi web3,eth,net,pubsub`', ipc: 'the `--ipcdisable` off' }; this.solutions = { 'Invalid JSON RPC response: (""|undefined)': { showOriginal: true, solution: '=> Possible fix: Make sure the Ethereum node is running and has the RPC apis enabled.' }, 'Method not found': { showOriginal: true, solution: "=> Possible fix: Parity must be run with ".concat(_parityRecommendedFlags[protocol], " to enable the necessary apis.") }, 'The method (\\w+) does not exist/is not available': { showOriginal: true, solution: "=> Possible fix: Geth must be run with ".concat(_gethRecommendedFlags[protocol], " to enable the necessary apis.") }, 'etherbase must be explicitly specified': { showOriginal: true, solution: '=> Possible fix: Geth must have at least one account created. Try running `geth account new`.' }, 'not supported': { showOriginal: true, solution: '=> Possible fix: Make sure the RPC apis are enabled. If you are running Geth in `light` mode, some methods are not supported.' }, 'Returned error: This request is not implemented yet. Please create an issue on Github repo.': { showOriginal: false, solution: '=> Parity does not support "sync" subscription if the WebSocket provider is used' } }; } _createClass(Error, [{ key: "getSolution", value: function getSolution(errorMessage) { var solution = ''; var solutionsRegexArray = Object.keys(this.solutions); for (var i = 0; i < solutionsRegexArray.length; i++) { if (errorMessage.match(RegExp(solutionsRegexArray[i], 'i'))) { if (this.solutions[solutionsRegexArray[i]].showOriginal) { solution = "".concat(errorMessage, " ").concat(this.solutions[solutionsRegexArray[i]].solution); } else { solution = this.solutions[solutionsRegexArray[i]].solution; } break; } } if (!solution) { solution = errorMessage; } return solution; } }, { key: "resolve", value: function resolve(error) { var solution = this.getSolution(error.message); return solution; } }]); return Error; }(); exports.default = Error;