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.



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

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

Instance Attribute Details

#messageObject



141
142
143
# File 'lib/restclient/exceptions.rb', line 141

def message
  @message || default_message
end

#original_exceptionObject

Returns the value of attribute original_exception.



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

def original_exception
  @original_exception
end

#responseObject

Returns the value of attribute response.



110
111
112
# File 'lib/restclient/exceptions.rb', line 110

def response
  @response
end

Instance Method Details

#default_messageObject



145
146
147
# File 'lib/restclient/exceptions.rb', line 145

def default_message
  self.class.name
end

#http_bodyObject



133
134
135
# File 'lib/restclient/exceptions.rb', line 133

def http_body
  @response.body if @response
end

#http_codeObject



120
121
122
123
124
125
126
127
# File 'lib/restclient/exceptions.rb', line 120

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

#http_headersObject



129
130
131
# File 'lib/restclient/exceptions.rb', line 129

def http_headers
  @response.headers if @response
end

#to_sObject



137
138
139
# File 'lib/restclient/exceptions.rb', line 137

def to_s
  message
end