Exception: RestClient::Exception

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/restclient/exceptions.rb

Overview

This is the base RestClient exception class. Rescue it if you want to catch any exception that your request might raise 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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Exception

Returns a new instance of Exception.



24
25
26
27
28
29
# File 'lib/restclient/exceptions.rb', line 24

def initialize response = nil
  @response = response

  # compatibility: this make the exception behave like a Net::HTTPResponse
  response.extend ResponseForException
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



22
23
24
# File 'lib/restclient/exceptions.rb', line 22

def message
  @message
end

#responseObject

Returns the value of attribute response.



22
23
24
# File 'lib/restclient/exceptions.rb', line 22

def response
  @response
end

Instance Method Details

#http_bodyObject



36
37
38
# File 'lib/restclient/exceptions.rb', line 36

def http_body
  @response
end

#http_codeObject



31
32
33
34
# File 'lib/restclient/exceptions.rb', line 31

def http_code
  # return integer for compatibility
  @response.code.to_i if @response
end

#inspectObject



40
41
42
# File 'lib/restclient/exceptions.rb', line 40

def inspect
  "#{self.class} : #{http_code} #{message}"
end