Exception: Savon::HTTP::Error

Inherits:
Error
  • Object
show all
Defined in:
lib/savon/http/error.rb

Overview

Savon::HTTP::Error

Represents an HTTP error. Contains the original HTTPI::Response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Error

Expects an HTTPI::Response.



13
14
15
# File 'lib/savon/http/error.rb', line 13

def initialize(http)
  self.http = http
end

Instance Attribute Details

#httpObject

Accessor for the HTTPI::Response.



18
19
20
# File 'lib/savon/http/error.rb', line 18

def http
  @http
end

Instance Method Details

#present?Boolean

Returns whether an HTTP error is present.

Returns:

  • (Boolean)


21
22
23
# File 'lib/savon/http/error.rb', line 21

def present?
  http.error?
end

#to_hashObject

Returns the HTTP response as a Hash.



36
37
38
# File 'lib/savon/http/error.rb', line 36

def to_hash
  @hash = { :code => http.code, :headers => http.headers, :body => http.body }
end

#to_sObject

Returns the HTTP error message.



26
27
28
29
30
31
32
33
# File 'lib/savon/http/error.rb', line 26

def to_s
  return "" unless present?
  
  @message ||= begin
    message = "HTTP error (#{http.code})"
    message << ": #{http.body}" unless http.body.empty?
  end
end