Exception: Jsonrpctcp::RPCError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/jsonrpctcp/errors.rb

Overview

A custom error for the library

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code, source) ⇒ RPCError

RPC erros allow quick access to the code, the message and the source error object returned by the server

Parameters:

  • message (String)

    Error message

  • code (Fixnum)

    Error code

  • source (Hash)

    Original error object



32
33
34
35
36
# File 'lib/jsonrpctcp/errors.rb', line 32

def initialize(message, code, source)
  @code = code
  @message = message
  @source_object = hash
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



26
27
28
# File 'lib/jsonrpctcp/errors.rb', line 26

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



26
27
28
# File 'lib/jsonrpctcp/errors.rb', line 26

def message
  @message
end

#source_objectObject (readonly)

Returns the value of attribute source_object.



26
27
28
# File 'lib/jsonrpctcp/errors.rb', line 26

def source_object
  @source_object
end

Class Method Details

.from_rpc_response(r) ⇒ Object

Creates a RPCError directly from a RPC response

Parameters:

  • r (Hash)

    a parsed response



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jsonrpctcp/errors.rb', line 40

def self.from_rpc_response(r)
  if r.nil? || !r.is_a?(Hash)
    return RPCError.new("Empty response",
                        nil,
                        {})
  else
    return RPCError.new(r['error']['message'],
                        r['error']['code'],
                        r)
  end
end