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.
-
#status_code ⇒ Object
readonly
Public: The HTTP status code of this error.
-
#type ⇒ Object
readonly
Public: The type of error.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(http_response) ⇒ HTTPError
constructor
Public: Initialize an error.
-
#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
51 52 53 54 55 56 57 |
# File 'lib/azure/core/http/http_error.rb', line 51 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
41 42 43 |
# File 'lib/azure/core/http/http_error.rb', line 41 def description @description end |
#detail ⇒ Object (readonly)
Public: Detail of the error
Returns a String
46 47 48 |
# File 'lib/azure/core/http/http_error.rb', line 46 def detail @detail end |
#status_code ⇒ Object (readonly)
Public: The HTTP status code of this error
Returns a Fixnum
29 30 31 |
# File 'lib/azure/core/http/http_error.rb', line 29 def status_code @status_code end |
#type ⇒ Object (readonly)
36 37 38 |
# File 'lib/azure/core/http/http_error.rb', line 36 def type @type end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
24 25 26 |
# File 'lib/azure/core/http/http_error.rb', line 24 def uri @uri end |
Instance Method Details
#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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/azure/core/http/http_error.rb', line 64 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? # 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 |