Exception: Riak::ProtobuffsFailedRequest

Inherits:
FailedRequest show all
Defined in:
lib/riak/errors/failed_request.rb

Overview

Exception raised when receiving an unexpected Protocol Buffers response from Riak

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(code, message) ⇒ ProtobuffsFailedRequest

Returns a new instance of ProtobuffsFailedRequest.



13
14
15
16
17
18
19
# File 'lib/riak/errors/failed_request.rb', line 13

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



12
13
14
# File 'lib/riak/errors/failed_request.rb', line 12

def code
  @code
end

#original_messageObject (readonly)

Returns the value of attribute original_message.



12
13
14
# File 'lib/riak/errors/failed_request.rb', line 12

def original_message
  @original_message
end

Instance Method Details

#bodyObject



42
43
44
# File 'lib/riak/errors/failed_request.rb', line 42

def body
  @original_message
end

#is_json?true, false

Returns whether the error response is in JSON.

Returns:

  • (true, false)

    whether the error response is in JSON



22
23
24
25
26
27
28
29
# File 'lib/riak/errors/failed_request.rb', line 22

def is_json?
  begin
    JSON.parse(@original_message)
    true
  rescue
    false
  end
end

#not_found?true, false

Returns whether the error represents a “not found” response.

Returns:

  • (true, false)

    whether the error represents a “not found” response



32
33
34
# File 'lib/riak/errors/failed_request.rb', line 32

def not_found?
  @not_found
end

#server_error?true, false

Returns whether the error represents an internal server error.

Returns:

  • (true, false)

    whether the error represents an internal server error



38
39
40
# File 'lib/riak/errors/failed_request.rb', line 38

def server_error?
  @server_error
end