Class: Cosmos::JsonRpcError

Inherits:
JsonRpc show all
Defined in:
lib/cosmos/io/json_rpc.rb

Overview

Represents a JSON Remote Procedure Call Error

Defined Under Namespace

Classes: ErrorCode

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from JsonRpc

#<=>, #as_json, #to_json

Constructor Details

#initialize(code, message, data = nil) ⇒ JsonRpcError

Returns a new instance of JsonRpcError.

Parameters:

  • code (Integer)

    The error type that occurred

  • message (String)

    A short description of the error

  • data (Hash) (defaults to: nil)

    Additional information about the error



385
386
387
388
389
390
# File 'lib/cosmos/io/json_rpc.rb', line 385

def initialize(code, message, data = nil)
  super()
  @hash['code'] = code
  @hash['message'] = message
  @hash['data'] = data
end

Class Method Details

.from_hash(hash) ⇒ JsonRpcError

Creates a JsonRpcError object from a Hash

Parameters:

  • hash (Hash)

    Hash containing the following keys: code, message, and optionally data

Returns:



412
413
414
415
416
417
418
# File 'lib/cosmos/io/json_rpc.rb', line 412

def self.from_hash(hash)
  if hash['code'] and (hash['code'].to_i == hash['code']) and hash['message']
    self.new(hash['code'], hash['message'], hash['data'])
  else
    raise "Invalid JSON-RPC 2.0 Error\n#{hash.inspect}\n"
  end
end

Instance Method Details

#codeInteger

Returns The error type that occurred.

Returns:

  • (Integer)

    The error type that occurred



393
394
395
# File 'lib/cosmos/io/json_rpc.rb', line 393

def code
  @hash['code']
end

#dataHash

Returns Additional information about the error.

Returns:

  • (Hash)

    Additional information about the error



403
404
405
# File 'lib/cosmos/io/json_rpc.rb', line 403

def data
  @hash['data']
end

#messageString

Returns A short description of the error.

Returns:

  • (String)

    A short description of the error



398
399
400
# File 'lib/cosmos/io/json_rpc.rb', line 398

def message
  @hash['message']
end