lib/jsonrpctcp/errors.rb in jsonrpctcp-1.0.1 vs lib/jsonrpctcp/errors.rb in jsonrpctcp-1.0.2
- old
+ new
@@ -22,11 +22,11 @@
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
+ # 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)
@@ -36,11 +36,17 @@
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)
+ 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
end
end