Exception: SisRuby::BadResponseError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ BadResponseError

Returns a new instance of BadResponseError.



7
8
9
# File 'lib/sis_ruby/exceptions/bad_response_error.rb', line 7

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/sis_ruby/exceptions/bad_response_error.rb', line 5

def response
  @response
end

Instance Method Details

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sis_ruby/exceptions/bad_response_error.rb', line 12

def to_s

  first_header_line = if response && response.options[:response_headers]
    header_lines = response.options[:response_headers].split("\r\n")
    header_lines.any? ? header_lines.first : nil
  else
    nil
  end

  body = if response && response.options[:response_body]
   response.options[:response_body].rstrip
  else
    nil
  end

  code = response.code

  string = "#{self.class.name}: #{code}"
  string << ": #{body}" if body
  string << (first_header_line ? " (#{first_header_line})" : '')
  string
end