@bigmi/core
Version:
TypeScript library for Bitcoin apps.
77 lines • 2.68 kB
JavaScript
import { BaseError } from './base.js';
/**
* @enum {number} RpcErrorCode
* @description JSON-RPC error codes
* @see https://www.jsonrpc.org/specification#error_object
*/
export var RpcErrorCode;
(function (RpcErrorCode) {
/**
* Parse error Invalid JSON
**/
RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
/**
* The JSON sent is not a valid Request object.
**/
RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
/**
* The method does not exist/is not available.
**/
RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
/**
* Invalid method parameter(s).
*/
RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
/**
* Internal JSON-RPC error.
* This is a generic error, used when the server encounters an error in performing the request.
**/
RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
/**
* user rejected/canceled the request
*/
RpcErrorCode[RpcErrorCode["USER_REJECTION"] = -32000] = "USER_REJECTION";
/**
* method is not supported for the address provided
*/
RpcErrorCode[RpcErrorCode["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
/**
* The client does not have permission to access the requested resource.
*/
RpcErrorCode[RpcErrorCode["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
/**
* Unknown generic errors
*/
RpcErrorCode[RpcErrorCode["MISC_ERROR"] = -1] = "MISC_ERROR";
})(RpcErrorCode || (RpcErrorCode = {}));
export class UserRejectedRequestError extends BaseError {
constructor(message) {
const name = 'UserRejectedRequestError';
const errMessage = message || 'The user rejected your request, please try again';
super(`${name}: ${errMessage}`, {
name,
});
this.code = RpcErrorCode.USER_REJECTION;
}
}
export class MethodNotSupportedRpcError extends BaseError {
constructor(method) {
const name = 'MethodNotSupportedError';
const message = `The method ${method} you are calling is not supported`;
super(`${name}: ${message}`, {
name,
});
this.code = RpcErrorCode.METHOD_NOT_SUPPORTED;
}
}
export class ParseError extends BaseError {
constructor(message) {
const name = 'ParseError';
const errMessage = message || 'Invalid JSON, there was an error parsing your request.';
super(`${name}: ${errMessage}`, {
name,
});
this.code = RpcErrorCode.PARSE_ERROR;
}
}
//# sourceMappingURL=rpc.js.map