Exception: RIQ::HTTPError
- Defined in:
- lib/riq/error.rb
Overview
Main error that includes info about the request and what went wrong.
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#message ⇒ Object
Returns the value of attribute message.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(resp) ⇒ HTTPError
constructor
A new instance of HTTPError.
-
#to_s ⇒ Object
used to print the error nicely.
Constructor Details
#initialize(resp) ⇒ HTTPError
Returns a new instance of HTTPError.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/riq/error.rb', line 20 def initialize(resp) # build response message = "\n[#{resp.code}] #{resp.} : " unless resp.parsed_response.nil? begin m = resp.parsed_response.fetch('errorMessage', 'no message') rescue # parse returned HTML reg = resp.parsed_response.match(/<pre>(.*)<\/pre>/) unless reg.nil? m = reg[1].strip else m = 'no message' end end += "<#{m}>" end # pull out request info req = resp.request unless req.nil? += "\n Request: #{req.http_method} #{req.last_uri.to_s}" unless req.raw_body.nil? += "\n #{req.raw_body}" end end @message = @response = resp end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
16 17 18 |
# File 'lib/riq/error.rb', line 16 def code @code end |
#message ⇒ Object
Returns the value of attribute message.
17 18 19 |
# File 'lib/riq/error.rb', line 17 def @message end |
#response ⇒ Object
Returns the value of attribute response.
18 19 20 |
# File 'lib/riq/error.rb', line 18 def response @response end |
Instance Method Details
#to_s ⇒ Object
used to print the error nicely
52 53 54 |
# File 'lib/riq/error.rb', line 52 def to_s @message || super end |