import { RPC_ERROR_CODES } from './rpc.js';
export class RpcError extends Error {
    rpcErrorCode;
    constructor(message, rpcErrorCode) {
        super(message);
        this.name = 'RpcError';
        this.rpcErrorCode = rpcErrorCode;
    }
}
export function isRpcError(error) {
    if (!error || typeof error !== 'object')
        return false;
    if (error instanceof RpcError)
        return true;
    if (!(error instanceof Error))
        return false;
    const carrier = error;
    return carrier.name === 'RpcError' && typeof carrier.rpcErrorCode === 'string' && carrier.rpcErrorCode.trim().length > 0;
}
export function createRpcCallError(opts) {
    if (typeof opts.errorCode === 'string' && opts.errorCode.length > 0) {
        return new RpcError(opts.error, opts.errorCode);
    }
    return new Error(opts.error);
}
export function readRpcErrorCode(error) {
    if (!error || typeof error !== 'object')
        return undefined;
    const carrier = error;
    return typeof carrier.rpcErrorCode === 'string' ? carrier.rpcErrorCode : undefined;
}
export function isRpcMethodNotAvailableError(error) {
    const code = readRpcErrorCode(error);
    return code === RPC_ERROR_CODES.METHOD_NOT_AVAILABLE;
}
export function isRpcMethodNotFoundError(error) {
    const code = readRpcErrorCode(error);
    return code === RPC_ERROR_CODES.METHOD_NOT_FOUND;
}
//# sourceMappingURL=rpcErrors.js.map