Exception: MetaRPC::RPCError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/metarpc/rpc_error.rb

Overview

RPC possible errors

Constant Summary collapse

CODE_TO_MESSAGE =
{
  parse_error: {
    code: -32_700,
    message: 'Invalid JSON was received by the server.'
  },
  invalid_request: {
    code: -32_600,
    message: 'The JSON sent is not a valid Request object.'
  },
  method_not_found: {
    code: -32_601,
    message: 'The method does not exist / is not available.'
  },
  invalid_params: {
    code: -32_602,
    message: 'Invalid method parameter(s).'
  },
  internal_error: {
    code: -32_603,
    message: 'Internal JSON-RPC error.'
  },
  server_error: {
    code: -32_000,
    message: 'Server error occurred.'
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ RPCError

Returns a new instance of RPCError.



33
34
35
36
37
38
39
# File 'lib/metarpc/rpc_error.rb', line 33

def initialize(code)
  if code.is_a?(Symbol)
    @code = code
  else
    @forced_code = code
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/metarpc/rpc_error.rb', line 4

def code
  @code
end

#forced_codeObject (readonly)

Returns the value of attribute forced_code.



4
5
6
# File 'lib/metarpc/rpc_error.rb', line 4

def forced_code
  @forced_code
end

Instance Method Details

#to_hObject



41
42
43
# File 'lib/metarpc/rpc_error.rb', line 41

def to_h
  forced_code || CODE_TO_MESSAGE[code]
end