Exception: Solace::Errors::RPCError

Inherits:
ConnectionError show all
Defined in:
lib/solace/errors/rpc_error.rb

Overview

Raised when the RPC node returns an error response.

This error is raised when the Solana RPC node successfully processes the HTTP request but returns an error in the JSON-RPC response. This includes errors like invalid parameters, insufficient funds, blockhash not found, and other RPC method-specific errors. The error message and code from the RPC response are included in the exception.

Examples:

Handling RPC errors

begin
  connection.send_transaction(transaction)
rescue Solace::Errors::RPCError => e
  puts "RPC error (code #{e.code}): #{e.message}"
end

See Also:

Since:

  • 0.0.1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, rpc_code:, rpc_message:, rpc_data: nil) ⇒ RPCError

Returns a new instance of RPCError.

Parameters:

  • message (String)

    The error message

  • rpc_code (Integer)

    The JSON-RPC error code

  • rpc_message (String)

    The JSON-RPC error message

  • rpc_data (Object) (defaults to: nil)

    The JSON-RPC error data

Since:

  • 0.0.1



29
30
31
32
33
34
# File 'lib/solace/errors/rpc_error.rb', line 29

def initialize(message, rpc_code:, rpc_message:, rpc_data: nil)
  super(message)
  @rpc_code = rpc_code
  @rpc_message = rpc_message
  @rpc_data = rpc_data
end

Instance Attribute Details

#rpc_codeObject (readonly)

Since:

  • 0.0.1



23
24
25
# File 'lib/solace/errors/rpc_error.rb', line 23

def rpc_code
  @rpc_code
end

#rpc_dataObject (readonly)

Since:

  • 0.0.1



23
24
25
# File 'lib/solace/errors/rpc_error.rb', line 23

def rpc_data
  @rpc_data
end

#rpc_messageObject (readonly)

Since:

  • 0.0.1



23
24
25
# File 'lib/solace/errors/rpc_error.rb', line 23

def rpc_message
  @rpc_message
end

Class Method Details

.format_response(response) ⇒ Solace::Errors::RPCError

Formats a response to an error

Parameters:

  • response (Hash)

    The JSON-RPC response

Returns:

Since:

  • 0.0.1



40
41
42
43
44
45
46
47
# File 'lib/solace/errors/rpc_error.rb', line 40

def self.format_response(response)
  new(
    "RPC error #{response['error']['code']}: #{response['error']['message']}",
    rpc_data: response['error']['data'],
    rpc_code: response['error']['code'],
    rpc_message: response['error']['message']
  )
end

Instance Method Details

#to_hHash

Returns The error as a hash.

Returns:

  • (Hash)

    The error as a hash

Since:

  • 0.0.1



50
# File 'lib/solace/errors/rpc_error.rb', line 50

def to_h = { code: rpc_code, message: rpc_message, data: rpc_data }