class Azure::Core::Http::HTTPError
Public: Class for handling all HTTP response errors
Attributes
description[R]
Public: Description of the error
Returns a String
detail[R]
Public: Detail of the error
Returns a String
header[R]
Public: The header name whose value is invalid
Returns a String
header_value[R]
Public: The invalid header value
Returns a String
http_response[R]
Public: Detail of the response
Returns an Azure::Core::Http::HttpResponse
object
status_code[R]
Public: The HTTP status code of this error
Returns a Fixnum
type[R]
uri[R]
Public: The request URI
Returns a String
Public Class Methods
new(http_response)
click to toggle source
Public: Initialize an error
http_response
- An Azure::Core::HttpResponse
Calls superclass method
# File lib/azure/core/http/http_error.rb, line 70 def initialize(http_response) @http_response = http_response @uri = http_response.uri @status_code = http_response.status_code parse_response # Use reason phrase as the description if description is empty @description = http_response.reason_phrase if (@description.nil? || @description.empty?) && http_response.reason_phrase super("#{type} (#{status_code}): #{description}") end
Public Instance Methods
inspect()
click to toggle source
# File lib/azure/core/http/http_error.rb, line 127 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_json_response()
click to toggle source
# File lib/azure/core/http/http_error.rb, line 114 def parse_json_response odata_error = JSON.parse(@http_response.body)['odata.error'] @type = odata_error['code'] @description = odata_error['message']['value'] end
parse_response()
click to toggle source
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
# File lib/azure/core/http/http_error.rb, line 85 def parse_response if @http_response.body && @http_response.respond_to?(:headers) && @http_response.headers['Content-Type'] if @http_response.headers['Content-Type'].include?('xml') parse_xml_response elsif @http_response.headers['Content-Type'].include?('json') parse_json_response end else parse_unknown_response end end
parse_unknown_response()
click to toggle source
# File lib/azure/core/http/http_error.rb, line 120 def parse_unknown_response @type = 'Unknown' if @http_response.body @description = "#{@http_response.body.strip}" end end
parse_xml_response()
click to toggle source
# File lib/azure/core/http/http_error.rb, line 97 def parse_xml_response 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? end