Exception: Azure::Core::Http::HTTPError

Inherits:
Error
  • Object
show all
Defined in:
lib/azure/storage/core/http/http_error.rb

Overview

Public: Class for handling all HTTP response errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ HTTPError

Public: Initialize an error

http_response - An Azure::Core::HttpResponse


50
51
52
53
54
55
56
# File 'lib/azure/storage/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

Instance Attribute Details

#descriptionObject (readonly)

Public: Description of the error

Returns a String


40
41
42
# File 'lib/azure/storage/core/http/http_error.rb', line 40

def description
  @description
end

#detailObject (readonly)

Public: Detail of the error

Returns a String


45
46
47
# File 'lib/azure/storage/core/http/http_error.rb', line 45

def detail
  @detail
end

#status_codeObject (readonly)

Public: The HTTP status code of this error

Returns a Fixnum


28
29
30
# File 'lib/azure/storage/core/http/http_error.rb', line 28

def status_code
  @status_code
end

#typeObject (readonly)

Public: The type of error

msdn.microsoft.com/en-us/library/azure/dd179357

Returns a String


35
36
37
# File 'lib/azure/storage/core/http/http_error.rb', line 35

def type
  @type
end

#uriObject (readonly)

Returns the value of attribute uri


23
24
25
# File 'lib/azure/storage/core/http/http_error.rb', line 23

def uri
  @uri
end

Instance Method Details

#parse_responseObject

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


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/azure/storage/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}"
    end
  end
end