class Restfolia::ResponseError

Public: Exception to represent an invalid HTTP response.

Examples

begin
  # assuming http_response is 404 response
  raise ResponseError.new("message", caller, http_response)
rescue Restfolia::ResponseError => ex
  ex.http_code # => 404
  ex.http_message # => "Not Found"
  ex.http_object # => http_response object
end

Constants

HTTP_CODE_MSG

List of HTTP Status code definitions. Source www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Attributes

http_code[R]

Returns nil or code from http_response instance

http_message[R]

Returns nil or status code definition from http_code

Public Class Methods

new(message, backtrace, http_response) click to toggle source

Public: Creates a ResponseError.

message - String to describe the error. backtrace - Array, usually mounted by Kernel#caller. http_response - Net::HTTPResponse with error.

Examples

begin
  # assuming http_response is 404 response
  raise ResponseError.new("message", caller, http_response)
rescue Restfolia::ResponseError => ex
  ex.http_code # => 404
  ex.http_message # => "Not Found"
  ex.http_object # => http_response object
end
Calls superclass method
# File lib/restfolia/exceptions.rb, line 89
def initialize(message, backtrace, http_response)
  super(message)
  self.set_backtrace(backtrace)

  @http_response = http_response
  @http_code, @http_message = nil
  if http_response.respond_to?(:code)
    @http_code = http_response.code.to_i
    @http_message = HTTP_CODE_MSG[@http_code] \
                    || "Unknown HTTP code (#{@http_code})"
  end
end

Public Instance Methods

http_object() click to toggle source

Returns nil or Net::HTTPResponse instance.

# File lib/restfolia/exceptions.rb, line 103
def http_object
  @http_response
end