Sha256: f187f9010eff49aa2d26d56b704b96225e849359f5d872c4f567c2e184b2979f

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

module Jsonrpctcp

  # A custom exception for the library
  class RPCException < Exception
  end

  # A custom error for the library
  class RPCError < StandardError
    attr_reader :code, :message, :source_object
    # RPC erros allow quick access to the code, the message and the 
    # source error object returned by the server
    # @param message [String] Error message
    # @param code [Fixnum] Error code
    # @param source [Hash] Original error object
    def initialize(message, code, source)
      @code = code
      @message = message
      @source_object = hash
    end

    # Creates a RPCError directly from a RPC response
    # @param r [Hash] a parsed response
    def self.from_rpc_response(r)
      return RPCError.new(r['error']['message'],
                          r['error']['code'], 
                          r)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonrpctcp-0.2.0 lib/jsonrpctcp/errors.rb