@arifwidianto/rpc-agent
Version:
RPC Agent for both client and server, extends more methods easily
35 lines (34 loc) • 1.85 kB
TypeScript
import { ErrorCode, ErrorDetails, JSONValue } from "../interfaces";
export declare class RpcError extends Error {
readonly code: ErrorCode;
readonly details?: Record<string, JSONValue>;
readonly timestamp: string;
readonly requestId?: string | number | null;
readonly source?: string;
readonly errorId: string;
constructor({ message, code, details, requestId, source, }: {
message: string;
code: ErrorCode;
details?: Record<string, JSONValue>;
requestId?: string | number | null;
source?: string;
});
toJSON(): ErrorDetails;
static fromJSON(json: ErrorDetails): RpcError;
}
export declare class ErrorService {
private static createError;
static parseError(message?: string, details?: Record<string, JSONValue>): RpcError;
static invalidRequest(message?: string, details?: Record<string, JSONValue>): RpcError;
static methodNotFound(message?: string, details?: Record<string, JSONValue>): RpcError;
static invalidParams(message: string, field?: string, details?: Record<string, JSONValue>): RpcError;
static internalError(message?: string, details?: Record<string, JSONValue>): RpcError;
static requestTimeout(message?: string, details?: Record<string, JSONValue>): RpcError;
static extensionNotFound(message?: string, details?: Record<string, JSONValue>): RpcError;
static serviceUnavailable(message?: string, details?: Record<string, JSONValue>): RpcError;
static unauthorized(message?: string, details?: Record<string, JSONValue>): RpcError;
static forbidden(message?: string, details?: Record<string, JSONValue>): RpcError;
static rateLimited(message?: string, details?: Record<string, JSONValue>): RpcError;
static isRpcError(error: unknown): error is RpcError;
static wrapError(error: unknown): RpcError;
}