Exception: Azure::Core::Http::HTTPError
- Defined in:
- lib/azure/core/http/http_error.rb
Overview
Public: Class for handling all HTTP response errors
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Public: Description of the error.
-
#detail ⇒ Object
readonly
Public: Detail of the error.
-
#header ⇒ Object
readonly
Public: The header name whose value is invalid.
-
#header_value ⇒ Object
readonly
Public: The invalid header value.
-
#http_response ⇒ Object
readonly
Public: Detail of the response.
-
#status_code ⇒ Object
readonly
Public: The HTTP status code of this error.
-
#type ⇒ Object
readonly
Public: The type of error.
-
#uri ⇒ Object
readonly
Public: The request URI.
Instance Method Summary collapse
-
#initialize(http_response) ⇒ HTTPError
constructor
Public: Initialize an error.
- #inspect ⇒ Object
-
#parse_response ⇒ Object
Extract the relevant information from the response’s body.
Constructor Details
#initialize(http_response) ⇒ HTTPError
Public: Initialize an error
http_response - An Azure::Core::HttpResponse
69 70 71 72 73 74 75 |
# File 'lib/azure/core/http/http_error.rb', line 69 def initialize(http_response) @http_response = http_response @uri = http_response.uri @status_code = http_response.status_code parse_response super("#{type} (#{status_code}): #{description}") end |
Instance Attribute Details
#description ⇒ Object (readonly)
Public: Description of the error
Returns a String
49 50 51 |
# File 'lib/azure/core/http/http_error.rb', line 49 def description @description end |
#detail ⇒ Object (readonly)
Public: Detail of the error
Returns a String
54 55 56 |
# File 'lib/azure/core/http/http_error.rb', line 54 def detail @detail end |
#header ⇒ Object (readonly)
Public: The header name whose value is invalid
Returns a String
59 60 61 |
# File 'lib/azure/core/http/http_error.rb', line 59 def header @header end |
#header_value ⇒ Object (readonly)
Public: The invalid header value
Returns a String
64 65 66 |
# File 'lib/azure/core/http/http_error.rb', line 64 def header_value @header_value end |
#http_response ⇒ Object (readonly)
Public: Detail of the response
Returns an Azure::Core::Http::HttpResponse object
27 28 29 |
# File 'lib/azure/core/http/http_error.rb', line 27 def http_response @http_response end |
#status_code ⇒ Object (readonly)
Public: The HTTP status code of this error
Returns a Fixnum
37 38 39 |
# File 'lib/azure/core/http/http_error.rb', line 37 def status_code @status_code end |
#type ⇒ Object (readonly)
44 45 46 |
# File 'lib/azure/core/http/http_error.rb', line 44 def type @type end |
#uri ⇒ Object (readonly)
Public: The request URI
Returns a String
32 33 34 |
# File 'lib/azure/core/http/http_error.rb', line 32 def uri @uri end |
Instance Method Details
#inspect ⇒ Object
109 110 111 112 113 |
# File 'lib/azure/core/http/http_error.rb', line 109 def inspect string = "#<#{self.class.name}:#{self.object_id} " fields = self.instance_variables.map{|field| "#{field}: #{self.send(field.to_s.delete("@")).inspect}"} string << fields.join(", ") << ">" end |
#parse_response ⇒ Object
Extract the relevant information from the response’s body. If the response body is not an XML, we return an ‘Unknown’ error with the entire body as the description
Returns nothing
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/azure/core/http/http_error.rb', line 82 def parse_response if @http_response.body && @http_response.body.include?('<') document = Nokogiri.Slop(@http_response.body) @type = document.css('code').first.text if document.css('code').any? @type = document.css('Code').first.text if document.css('Code').any? @description = document.css('message').first.text if document.css('message').any? @description = document.css('Message').first.text if document.css('Message').any? @header = document.css('headername').first.text if document.css('headername').any? @header = document.css('HeaderName').first.text if document.css('HeaderName').any? @header_value = document.css('headervalue').first.text if document.css('headervalue').any? @header_value = document.css('HeaderValue').first.text if document.css('HeaderValue').any? # service bus uses detail instead of message @detail = document.css('detail').first.text if document.css('detail').any? @detail = document.css('Detail').first.text if document.css('Detail').any? else @type = 'Unknown' if @http_response.body @description = "#{@http_response.body.strip}" end end end |