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



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

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



113
114
115
# File 'lib/soda/exceptions.rb', line 113

def default_message
  self.class.name
end

#http_bodyObject



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

def http_body
  @response.body if @response
end

#http_codeObject



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

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

#http_headersObject



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

def http_headers
  @response.headers if @response
end

#to_sObject



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

def to_s
  message
end