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

status_code[R]

Public: The HTTP status code of this error

Returns a Fixnum

type[R]
uri[R]

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 50
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

Public Instance Methods

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 63
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
    else
      @description = @http_response.message.strip
    end
  end
end