Exception: Restfolia::ResponseError
- Inherits:
-
StandardError
- Object
- StandardError
- Restfolia::ResponseError
- Defined in:
- lib/restfolia/exceptions.rb
Overview
Constant Summary collapse
- HTTP_CODE_MSG =
List of HTTP Status code definitions. Source www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
{ # 2xx 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', # 3xx 300 => 'Multiple Choices', 301 => 'MovedPermanently', 302 => 'Found', 303 => 'SeeOther', 304 => 'NotModified', 305 => 'UseProxy', 306 => '(Unused)', 307 => 'TemporaryRedirect', # 4xx 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', # 5xx 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported' }
Instance Attribute Summary collapse
-
#http_code ⇒ Object
readonly
Returns nil or #code from http_response instance.
-
#http_message ⇒ Object
readonly
Returns nil or status code definition from #http_code.
Instance Method Summary collapse
-
#http_object ⇒ Object
Returns nil or Net::HTTPResponse instance.
-
#initialize(message, backtrace, http_response) ⇒ ResponseError
constructor
Public: Creates a ResponseError.
Constructor Details
#initialize(message, backtrace, http_response) ⇒ ResponseError
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. # => "Not Found"
ex.http_object # => http_response object
end
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/restfolia/exceptions.rb', line 89 def initialize(, backtrace, http_response) super() 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 |
Instance Attribute Details
#http_code ⇒ Object (readonly)
Returns nil or #code from http_response instance
19 20 21 |
# File 'lib/restfolia/exceptions.rb', line 19 def http_code @http_code end |
#http_message ⇒ Object (readonly)
Returns nil or status code definition from #http_code
22 23 24 |
# File 'lib/restfolia/exceptions.rb', line 22 def @http_message end |
Instance Method Details
#http_object ⇒ Object
Returns nil or Net::HTTPResponse instance.
103 104 105 |
# File 'lib/restfolia/exceptions.rb', line 103 def http_object @http_response end |