Sha256: 3d56e73632439cd9c4fa77e7685bd9e1170b2e29be18c8613345d9353041b884

Contents?: true

Size: 1.56 KB

Versions: 28

Compression:

Stored size: 1.56 KB

Contents

module GorgonAMQ
  module Protocol
    class Error < StandardError
      DEFAULT_MESSAGE = "AMQP error".freeze

      def self.inherited(subclass)
        @_subclasses ||= []
        @_subclasses << subclass
      end # self.inherited(subclazz)

      def self.subclasses_with_values
        @_subclasses.select{ |k| defined?(k::VALUE) }
      end # self.subclasses_with_values

      def self.[](code)
        if result = subclasses_with_values.detect { |klass| klass::VALUE == code }
          result
        else
          raise "No such exception class for code #{code}" unless result
        end # if
      end # self.[]

      def initialize(message = self.class::DEFAULT_MESSAGE)
        super(message)
      end
    end

    class FrameTypeError < Protocol::Error
      def initialize(types)
        super("Must be one of #{types.inspect}")
      end
    end

    class EmptyResponseError < Protocol::Error
      DEFAULT_MESSAGE = "Empty response received from the server."

      def initialize(message = self.class::DEFAULT_MESSAGE)
        super(message)
      end
    end

    class BadResponseError < Protocol::Error
      def initialize(argument, expected, actual)
        super("Argument #{argument} has to be #{expected.inspect}, was #{data.inspect}")
      end
    end

    class SoftError < Protocol::Error
      def self.inherited(subclass)
        Error.inherited(subclass)
      end # self.inherited(subclass)
    end

    class HardError < Protocol::Error
      def self.inherited(subclass)
        Error.inherited(subclass)
      end # self.inherited(subclass)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gorgon-0.11.1 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.11.0 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.5 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.4 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.3 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.2 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.1 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.10.0 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.9.0 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.8.4 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.8.3 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.8.2 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.8.1 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.8.0 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.1 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.0 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.0.rc4 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.0.rc3 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.0.rc2 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb
gorgon-0.7.0.rc1 lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb