Sha256: d9fa14e035ec99500b9847507dcd4eb97cafbf80d2c1873f78f6edad5f0bda76

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pipe_rpc-1.0.0 lib/pipe_rpc/client_request_error_response.rb