Sha256: bcc0e08a9892ce1e777a38bc875e06949c4c14984c2c5963125531b5612c2d8d

Contents?: true

Size: 1.4 KB

Versions: 13

Compression:

Stored size: 1.4 KB

Contents

require 'riak/errors/base'

module Riak
  class FailedRequest < Error
    def initialize(message)
      super(message ||  t('failed_request'))
    end
  end

  # Exception raised when receiving an unexpected Protocol Buffers response from Riak
  class ProtobuffsFailedRequest < FailedRequest
    attr_reader :code, :original_message
    def initialize(code, message)
      super t('protobuffs_failed_request', :code => code, :body => message)
      @original_message = message
      @code = code
      @not_found = code == :not_found
      @server_error = code == :server_error
    end

    # @return [true, false] whether the error response is in JSON
    def is_json?
      begin
        JSON.parse(@original_message)
        true
      rescue
        false
      end
    end

    # @return [true,false] whether the error represents a "not found" response
    def not_found?
      @not_found
    end

    # @return [true,false] whether the error represents an internal
    #   server error
    def server_error?
      @server_error
    end

    def body
      @original_message
    end
  end

  class ProtobuffsUnexpectedResponse < ProtobuffsFailedRequest
    def initialize(code, expected)
      super code, t('pbc.unexpected_response', expected: expected, actual: code)
    end
  end

  class ProtobuffsErrorResponse < ProtobuffsFailedRequest
    def initialize(payload)
      super payload.errcode, payload.errmsg
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
riak-client-2.6.0 lib/riak/errors/failed_request.rb
riak-client-2.5.0 lib/riak/errors/failed_request.rb
riak-client-2.4.1 lib/riak/errors/failed_request.rb
riak-client-2.4.0 lib/riak/errors/failed_request.rb
riak-client-2.4.0.pre1 lib/riak/errors/failed_request.rb
riak-client-2.3.2 lib/riak/errors/failed_request.rb
riak-client-2.3.1 lib/riak/errors/failed_request.rb
riak-client-2.3.0 lib/riak/errors/failed_request.rb
riak-client-2.2.2 lib/riak/errors/failed_request.rb
riak-client-2.2.1 lib/riak/errors/failed_request.rb
riak-client-noenc-1.0.0 lib/riak/errors/failed_request.rb
riak-client-2.2.0 lib/riak/errors/failed_request.rb
riak-client-2.2.0.pre1 lib/riak/errors/failed_request.rb