Exception: Riak::HTTPFailedRequest

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

Overview

Exception raised when the expected HTTP response code from Riak fails to match the actual response code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(method, expected_code, received_code, headers, body) ⇒ HTTPFailedRequest

Returns a new instance of HTTPFailedRequest.



30
31
32
33
# File 'lib/riak/failed_request.rb', line 30

def initialize(method, expected_code, received_code, headers, body)
  @method, @expected, @code, @headers, @body = method, expected_code, received_code, headers, body
  super t("http_failed_request", :expected => @expected.inspect, :code => @code, :body => @body)
end

Instance Attribute Details

#bodyString (readonly)

Returns the response body, if present.

Returns:

  • (String)

    the response body, if present



28
29
30
# File 'lib/riak/failed_request.rb', line 28

def body
  @body
end

#codeFixnum (readonly)

Returns the received response code.

Returns:

  • (Fixnum)

    the received response code



24
25
26
# File 'lib/riak/failed_request.rb', line 24

def code
  @code
end

#expectedFixnum (readonly)

Returns the expected response code.

Returns:

  • (Fixnum)

    the expected response code



22
23
24
# File 'lib/riak/failed_request.rb', line 22

def expected
  @expected
end

#headersHash (readonly)

Returns the response headers.

Returns:

  • (Hash)

    the response headers



26
27
28
# File 'lib/riak/failed_request.rb', line 26

def headers
  @headers
end

#methodSymbol (readonly)

Returns the HTTP method, one of :head, :get, :post, :put, :delete.

Returns:

  • (Symbol)

    the HTTP method, one of :head, :get, :post, :put, :delete



20
21
22
# File 'lib/riak/failed_request.rb', line 20

def method
  @method
end

Instance Method Details

#is_json?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/riak/failed_request.rb', line 35

def is_json?
  headers['content-type'].include?('application/json')
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



40
41
42
# File 'lib/riak/failed_request.rb', line 40

def not_found?
  @code.to_i == 404
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



46
47
48
# File 'lib/riak/failed_request.rb', line 46

def server_error?
  @code.to_i == 500
end