UNPKG

@open-rpc/schema-utils-js

Version:

<center> <span> <img alt="CircleCI branch" src="https://img.shields.io/circleci/project/github/open-rpc/schema-utils-js/master.svg"> <img src="https://codecov.io/gh/open-rpc/schema-utils-js/branch/master/graph/badge.svg" /> <img alt="npm" sr

59 lines (58 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Provides an error interface for handling when a method is trying to be called but does not exist. */ var MethodNotFoundError = /** @class */ (function () { /** * @param methodName The method name that was used. * @param openrpcDocument The OpenRPC document that the method was used against. * @param receievedParams The params, if any, that were used. */ function MethodNotFoundError(methodName, openrpcDocument, // eslint-disable-next-line @typescript-eslint/no-explicit-any receievedParams) { if (receievedParams === void 0) { receievedParams = []; } this.methodName = methodName; this.openrpcDocument = openrpcDocument; this.receievedParams = receievedParams; this.name = "MethodNotFoundError"; var msg = [ "Method Not Found Error for OpenRPC API named \"".concat(openrpcDocument.info.title, "\""), "The requested method: \"".concat(methodName, "\" not a valid method."), ]; if (openrpcDocument.methods.length > 0) { msg.push("Valid method names are as follows: ".concat(openrpcDocument.methods .map(function (_a) { var name = _a.name; return name; }) .join(", "))); } var stringedParams; if (receievedParams instanceof Array) { if (receievedParams.length > 0) { stringedParams = receievedParams .map(function (p) { try { return JSON.stringify(p); } catch (e) { return p; } }) .join("\n"); } } else { stringedParams = JSON.stringify(receievedParams); } if (stringedParams) { msg.push("Params:"); msg.push(stringedParams); } this.message = msg.join("\n"); } return MethodNotFoundError; }()); exports.default = MethodNotFoundError;