UNPKG

@unstoppabledomains/resolution

Version:
79 lines (78 loc) 4.34 kB
"use strict"; 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 __()); }; })(); var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigurationError = exports.ConfigurationErrorCode = void 0; var ConfigurationErrorCode; (function (ConfigurationErrorCode) { ConfigurationErrorCode["IncorrectProvider"] = "IncorrectProvider"; ConfigurationErrorCode["UnsupportedNetwork"] = "UnsupportedNetwork"; ConfigurationErrorCode["UnspecifiedUrl"] = "UnspecifiedUrl"; ConfigurationErrorCode["NetworkConfigMissing"] = "NetworkConfigMissing"; ConfigurationErrorCode["CustomNetworkConfigMissing"] = "CustomNetworkConfigMissing"; ConfigurationErrorCode["InvalidConfigurationField"] = "InvalidProxyReader"; ConfigurationErrorCode["DependencyMissing"] = "DependencyMissing"; })(ConfigurationErrorCode = exports.ConfigurationErrorCode || (exports.ConfigurationErrorCode = {})); /** * @internal * Internal Mapping object from ConfigurationErrorCode to a ConfigurationErrorHandler */ var HandlersByCode = (_a = {}, _a[ConfigurationErrorCode.IncorrectProvider] = function () { return "Provider doesn't implement sendAsync or send method"; }, _a[ConfigurationErrorCode.UnsupportedNetwork] = function (params) { return "Unsupported network in Resolution ".concat(params.method || '', " configuration"); }, _a[ConfigurationErrorCode.UnspecifiedUrl] = function (params) { return "Unspecified url in Resolution ".concat(params.method, " configuration"); }, _a[ConfigurationErrorCode.NetworkConfigMissing] = function (params) { return "Missing configuration in Resolution ".concat(params.method, ". Please specify ").concat(params.config); }, _a[ConfigurationErrorCode.CustomNetworkConfigMissing] = function (params) { return "Missing configuration in Resolution ".concat(params.method, ". Please specify ").concat(params.config, " when using a custom network"); }, _a[ConfigurationErrorCode.InvalidConfigurationField] = function (params) { return "Invalid '".concat(params.field, "' in Resolution ").concat(params.method); }, _a[ConfigurationErrorCode.DependencyMissing] = function (params) { return "Missing dependency for this functionality. Please install ".concat(params.dependency, " @ ").concat(params.version, " via npm or yarn"); }, _a); /** * Configuration Error class is designed to control every error being thrown by wrong configurations for objects * @param code - Error Code * - IncorrectProvider - When provider doesn't have implemented send or sendAsync methods * - UnsupportedNetwork - When network is not specified or not supported * - UnspecifiedUrl - When url is not specified for custom naming service configurations * - CustomNetworkConfigMissing - When configuration is missing for custom network configurations * @param method - optional param to specify which namingService errored out */ var ConfigurationError = /** @class */ (function (_super) { __extends(ConfigurationError, _super); function ConfigurationError(code, options) { if (options === void 0) { options = {}; } var _this = this; var configurationErrorHandler = HandlersByCode[code]; _this = _super.call(this, configurationErrorHandler(options)) || this; _this.code = code; _this.method = options.method; _this.name = 'ConfigurationError'; Object.setPrototypeOf(_this, ConfigurationError.prototype); return _this; } return ConfigurationError; }(Error)); exports.ConfigurationError = ConfigurationError; exports.default = ConfigurationError;