Exception: RestClient::RequestFailed
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- RestClient::RequestFailed
- Defined in:
- lib/request_errors.rb
Overview
The request failed, meaning the remote HTTP server returned a code other than success, unauthorized, or redirect.
The exception message attempts to extract the error from the XML, using format returned by Rails: <errors><error>some message</error></errors>
You can get the status code by e.http_code, or see anything about the response via e.response. For example, the entire result body (which is probably an HTML error page) is e.response.body.
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #http_code ⇒ Object
-
#initialize(response = nil) ⇒ RequestFailed
constructor
A new instance of RequestFailed.
- #message(default = "Unknown error, HTTP status code #{http_code}") ⇒ Object
- #parse_error_xml ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ RequestFailed
Returns a new instance of RequestFailed.
31 32 33 |
# File 'lib/request_errors.rb', line 31 def initialize(response=nil) @response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
29 30 31 |
# File 'lib/request_errors.rb', line 29 def response @response end |
Instance Method Details
#http_code ⇒ Object
35 36 37 |
# File 'lib/request_errors.rb', line 35 def http_code @response.code.to_i if @response end |
#message(default = "Unknown error, HTTP status code #{http_code}") ⇒ Object
39 40 41 42 |
# File 'lib/request_errors.rb', line 39 def (default="Unknown error, HTTP status code #{http_code}") return default unless @response parse_error_xml rescue default end |
#parse_error_xml ⇒ Object
44 45 46 47 |
# File 'lib/request_errors.rb', line 44 def parse_error_xml xml_errors = REXML::Document.new(@response.body).elements.to_a("//errors/error") xml_errors.empty? ? raise : xml_errors.map { |a| a.text }.join(" / ") end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/request_errors.rb', line 49 def to_s end |