# encoding: utf-8 # (c) 2011-2015 Martin Poljak (martin@poljak.cz) require "json-rpc-objects/v11/alt/error" require "json-rpc-objects/exceptions/invalid-code" ## # Main JSON-RPC Objects module. # module JsonRpcObjects ## # Module of JSON-RPC 2.0. # @see http://groups.google.com/group/json-rpc/web/json-rpc-2-0 # module V20 ## # Error description object class for Response. # class Error < JsonRpcObjects::V11::Alt::Error ## # Holds link to its version module. # VERSION = JsonRpcObjects::V20 ## # Indicates data member name. # DATA_MEMBER_NAME = :data ## # Checks correctness of the data. # def check! self.normalize! if ((-32768..-32000).include?(@code)) and not ((@code == -32700) or ((-32603..-32600).include?(@code)) or ((-32099..-32000).include?(code))) raise JsonRpcObjects::Exceptions::InvalidCode::new("Code is invalid because of reserved space.") end end ## # Renders data to output hash. # @return [Hash] with data of error # def output result = super() if result.include? "error" result["data"] = result["error"] result.delete("error") end return result end protected ## # Assigns error data. # def __assign_data(data) @data = data[:data] data.delete(:data) if @data.nil? super(data) end end end end end