Exception: SODA::Exception

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

Overview

This is the base 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.



82
83
84
85
86
# File 'lib/soda/exceptions.rb', line 82

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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



79
80
81
# File 'lib/soda/exceptions.rb', line 79

def data
  @data
end

#messageObject



106
107
108
# File 'lib/soda/exceptions.rb', line 106

def message
  @message || default_message
end

#original_exceptionObject

Returns the value of attribute original_exception.



78
79
80
# File 'lib/soda/exceptions.rb', line 78

def original_exception
  @original_exception
end

#responseObject

Returns the value of attribute response.



77
78
79
# File 'lib/soda/exceptions.rb', line 77

def response
  @response
end

Instance Method Details

#default_messageObject



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

def default_message
  self.class.name
end

#http_bodyObject



98
99
100
# File 'lib/soda/exceptions.rb', line 98

def http_body
  @response.body if @response
end

#http_codeObject



88
89
90
91
92
# File 'lib/soda/exceptions.rb', line 88

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

#http_headersObject



94
95
96
# File 'lib/soda/exceptions.rb', line 94

def http_headers
  @response.headers if @response
end

#to_sObject



102
103
104
# File 'lib/soda/exceptions.rb', line 102

def to_s
  message
end