Exception: Riak::HTTPFailedRequest
- Inherits:
-
FailedRequest
- Object
- StandardError
- FailedRequest
- Riak::HTTPFailedRequest
- 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
-
#body ⇒ String
readonly
The response body, if present.
-
#code ⇒ Fixnum
readonly
The received response code.
-
#expected ⇒ Fixnum
readonly
The expected response code.
-
#headers ⇒ Hash
readonly
The response headers.
-
#method ⇒ Symbol
readonly
The HTTP method, one of :head, :get, :post, :put, :delete.
Instance Method Summary collapse
-
#initialize(method, expected_code, received_code, headers, body) ⇒ HTTPFailedRequest
constructor
A new instance of HTTPFailedRequest.
- #is_json? ⇒ Boolean
-
#not_found? ⇒ true, false
Whether the error represents a “not found” response.
-
#server_error? ⇒ true, false
Whether the error represents an internal server error.
Methods included from Util::Translation
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
#body ⇒ String (readonly)
Returns the response body, if present.
28 29 30 |
# File 'lib/riak/failed_request.rb', line 28 def body @body end |
#code ⇒ Fixnum (readonly)
Returns the received response code.
24 25 26 |
# File 'lib/riak/failed_request.rb', line 24 def code @code end |
#expected ⇒ Fixnum (readonly)
Returns the expected response code.
22 23 24 |
# File 'lib/riak/failed_request.rb', line 22 def expected @expected end |
#headers ⇒ Hash (readonly)
Returns the response headers.
26 27 28 |
# File 'lib/riak/failed_request.rb', line 26 def headers @headers end |
#method ⇒ Symbol (readonly)
Returns 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
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.
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.
46 47 48 |
# File 'lib/riak/failed_request.rb', line 46 def server_error? @code.to_i == 500 end |