Exception: Riak::HTTPFailedRequest

Inherits:
FailedRequest show all
Defined in:
riak-client/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

- (HTTPFailedRequest) initialize(method, expected_code, received_code, headers, body)

A new instance of HTTPFailedRequest



43
44
45
46
# File 'riak-client/lib/riak/failed_request.rb', line 43

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

- (String) body (readonly)

The response body, if present

Returns:

  • (String)

    the response body, if present



41
42
43
# File 'riak-client/lib/riak/failed_request.rb', line 41

def body
  @body
end

- (Fixnum) code (readonly)

The received response code

Returns:

  • (Fixnum)

    the received response code



37
38
39
# File 'riak-client/lib/riak/failed_request.rb', line 37

def code
  @code
end

- (Fixnum) expected (readonly)

The expected response code

Returns:

  • (Fixnum)

    the expected response code



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

def expected
  @expected
end

- (Hash) headers (readonly)

The response headers

Returns:

  • (Hash)

    the response headers



39
40
41
# File 'riak-client/lib/riak/failed_request.rb', line 39

def headers
  @headers
end

- (Symbol) method (readonly)

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

Returns:

  • (Symbol)

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



33
34
35
# File 'riak-client/lib/riak/failed_request.rb', line 33

def method
  @method
end

Instance Method Details

- (Boolean) is_json?

Returns:



48
49
50
# File 'riak-client/lib/riak/failed_request.rb', line 48

def is_json?
  headers['content-type'].include?('application/json')
end

- (true, false) not_found?

Whether the error represents a “not found” response

Returns:

  • (true, false)

    whether the error represents a “not found” response



53
54
55
# File 'riak-client/lib/riak/failed_request.rb', line 53

def not_found?
  @code.to_i == 404
end

- (true, false) server_error?

Whether the error represents an internal server error

Returns:

  • (true, false)

    whether the error represents an internal server error



59
60
61
# File 'riak-client/lib/riak/failed_request.rb', line 59

def server_error?
  @code.to_i == 500
end