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, initial_response_code = nil) ⇒ Exception

Returns a new instance of Exception.



86
87
88
89
90
91
92
93
# File 'lib/restclient/exceptions.rb', line 86

def initialize response = nil, initial_response_code = nil
  @response = response
  @message = nil
  @initial_response_code = initial_response_code

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

Instance Attribute Details

#messageObject



116
117
118
# File 'lib/restclient/exceptions.rb', line 116

def message
  @message || self.class.name
end

#responseObject

Returns the value of attribute response.



83
84
85
# File 'lib/restclient/exceptions.rb', line 83

def response
  @response
end

Instance Method Details

#http_bodyObject



104
105
106
# File 'lib/restclient/exceptions.rb', line 104

def http_body
  @response.body if @response
end

#http_codeObject



95
96
97
98
99
100
101
102
# File 'lib/restclient/exceptions.rb', line 95

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

#inspectObject



108
109
110
# File 'lib/restclient/exceptions.rb', line 108

def inspect
  "#{message}: #{http_body}"
end

#to_sObject



112
113
114
# File 'lib/restclient/exceptions.rb', line 112

def to_s
  inspect
end