Sha256: 3acd2341c89f959870493bfb0ab5de359d61fcdaf9e58ce9cedc7be40ff35c95

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

module BERTRPC
  class BERTRPCError < StandardError
    attr_accessor :code, :original_exception

    def initialize(msg = nil, klass = nil, bt = [])
      case msg
        when Array
          code, message = msg
        else
          code, message = [0, msg]
      end

      if klass
        self.original_exception = RemoteError.new("#{klass}: #{message}")
        self.original_exception.set_backtrace(bt)
      end

      self.code = code
      super(message)
    end
  end

  class RemoteError < StandardError

  end

  class ConnectionError < BERTRPCError

  end

  # Raised when we don't get a response from a server in a timely
  # manner. This typically occurs in spite of a successful connection.
  class ReadTimeoutError < BERTRPCError
    attr_reader :host, :port, :timeout
    def initialize(host, port, timeout)
      @host, @port, @timeout = host, port, timeout
      super("No response from #{host}:#{port} in #{timeout}s")
    end
  end

  class ProtocolError < BERTRPCError
    NO_HEADER = [0, "Unable to read length header from server."]
    NO_DATA = [1, "Unable to read data from server."]
  end

  class ServerError < BERTRPCError

  end

  class UserError < BERTRPCError

  end

  class ProxyError < BERTRPCError

  end

  class InvalidOption < BERTRPCError

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bertrpc-0.4.2 lib/bertrpc/errors.rb
bertrpc-1.1.2 lib/bertrpc/errors.rb
bertrpc-0.4.1 lib/bertrpc/errors.rb