Sha256: c262ecc2946066505a67d9cae3c9a473cabb3a9fb1a1a390e271e9522c0cd338

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

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
      NoMethodError.new("undefined method `#{@data.fetch(:method)}' for <Client:#{@request.server}>")
    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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pipe_rpc-2.4.0 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.3.0 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.2.3 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.2.2 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.2.1 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.2.0 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.1.0 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-2.0.0 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-1.1.2 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-1.1.1 lib/pipe_rpc/client_request_error_response.rb
pipe_rpc-1.1.0 lib/pipe_rpc/client_request_error_response.rb