UNPKG

@stencila/jesta

Version:

Stencila plugin for executable documents using JavaScript

73 lines (72 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CapabilityError = exports.ServerError = exports.InvalidParamError = exports.MethodNotFoundError = exports.InvalidRequestError = exports.ParseError = exports.JsonRpcError = void 0; /** * Base class for JSON-RPC errors * * The default code is the code for a generic server error. * See https://www.jsonrpc.org/specification#error_object */ class JsonRpcError extends Error { constructor(name, code, message, data) { super(message); this.name = name; this.code = code; this.data = data; } } exports.JsonRpcError = JsonRpcError; /** * An error when a client sends invalid JSON */ class ParseError extends JsonRpcError { constructor(details) { super('ParseError', -32700, `Error while parsing request: ${details}`, details); } } exports.ParseError = ParseError; /** * An error when a client sends an invalid request */ class InvalidRequestError extends JsonRpcError { constructor() { super('InvalidRequestError', -32600, 'Request is invalid because it is missing an id or method'); } } exports.InvalidRequestError = InvalidRequestError; /** * An error when the requested method does not exist */ class MethodNotFoundError extends JsonRpcError { constructor(method) { super('MethodNotFoundError', -32601, `Method '${method}' does not exist`, method); } } exports.MethodNotFoundError = MethodNotFoundError; /** * An error when one of more parameters are invalid */ class InvalidParamError extends JsonRpcError { constructor(message, errors) { super('InvalidParamError', -32602, message, errors); } } exports.InvalidParamError = InvalidParamError; /** * A generic internal server error */ class ServerError extends JsonRpcError { constructor(message) { super('ServerError', -32000, message); } } exports.ServerError = ServerError; /** * An error when the plugin lacks the requested capability */ class CapabilityError extends JsonRpcError { constructor(capability, params) { super('CapabilityError', -32001, `Incapable of ${capability}`, params); } } exports.CapabilityError = CapabilityError;