Module: RightScale::HttpExceptions
- Defined in:
- lib/right_agent/http_exceptions.rb
Overview
Exceptions created for each status code defined in RestClient::STATUSES e.g., RightScale::HttpExceptions::ResourceNotFound for status code 404
Defined Under Namespace
Classes: RequestFailed
Constant Summary collapse
- HTTP_EXCEPTIONS_MAP =
Map HTTP status codes to the corresponding exception class
{}
Class Method Summary collapse
-
.convert(e) ⇒ Object
Convert RestClient exception.
-
.create(code, body = "", headers = {}) ⇒ Object
Create exception for given code.
Class Method Details
.convert(e) ⇒ Object
Convert RestClient exception
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/right_agent/http_exceptions.rb', line 71 def self.convert(e) e2 = if e.is_a?(RestClient::RequestTimeout) # Special case RequestTimeout because http_code and http_body is typically nil given no actual response create(408) else create(e.http_code, e.http_body, RightScale::Response.new((e.response && e.response.headers) || {})) end e2. = e. e2 end |
.create(code, body = "", headers = {}) ⇒ Object
Create exception for given code
62 63 64 65 66 67 68 |
# File 'lib/right_agent/http_exceptions.rb', line 62 def self.create(code, body = "", headers = {}) if HttpExceptions::HTTP_EXCEPTIONS_MAP[code] HttpExceptions::HTTP_EXCEPTIONS_MAP[code].new(code, body, RightScale::Response.new(headers)) else RequestFailed.new(code, body, RightScale::Response.new(headers)) end end |