class PipeRpc::ErrorResponse; end module PipeRpc class Client::Request::ErrorResponse < ErrorResponse def initialize(request, body) @request = request super body end def to_result case @code when -32601 then no_method_error when -32602 then argument_error when -32603 then internal_error when -32604 then no_server_error when -32605 then reflected_error else unknown_error end end private def no_method_error method = @data.fetch(:method) args = @data.fetch(:args) NoMethodError.new("undefined method `#{method}' for ", method, args) end def argument_error ArgumentError.new(@data.fetch(:message)) end def no_server_error NoServerError.new("undefined server `#{@request.server}'") end def internal_error InternalError.new(@data[:message]).tap do |error| error.set_backtrace(@data[:backtrace]) if error.respond_to? :set_backtrace end end def reflected_error ReflectedError.new(@data[:message]).tap do |error| error.set_backtrace(@data[:backtrace]) if error.respond_to? :set_backtrace end end def unknown_error UnknownError.new(@data[:message]) end end end