Exception: Aliyun::STS::ServerError

Inherits:
Common::Exception show all
Defined in:
lib/aliyun/sts/exception.rb

Overview

ServerError represents exceptions from the STS service. i.e. Client receives a HTTP response whose status is NOT OK. #message provides the error message and #to_s gives detailed information probably including the STS request id.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ServerError

Returns a new instance of ServerError.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aliyun/sts/exception.rb', line 16

def initialize(response)
  @http_code = response.code
  @attrs = {}

  doc = Nokogiri::XML(response.body) do |config|
    config.options |= Nokogiri::XML::ParseOptions::NOBLANKS
  end rescue nil

  if doc and doc.root
    doc.root.children.each do |n|
      @attrs[n.name] = n.text
    end
  end

  @error_code = @attrs['Code']
  @message = @attrs['Message']
  @request_id = @attrs['RequestId']
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



14
15
16
# File 'lib/aliyun/sts/exception.rb', line 14

def error_code
  @error_code
end

#http_codeObject (readonly)

Returns the value of attribute http_code.



14
15
16
# File 'lib/aliyun/sts/exception.rb', line 14

def http_code
  @http_code
end

#messageObject (readonly)

Returns the value of attribute message.



14
15
16
# File 'lib/aliyun/sts/exception.rb', line 14

def message
  @message
end

#request_idObject (readonly)

Returns the value of attribute request_id.



14
15
16
# File 'lib/aliyun/sts/exception.rb', line 14

def request_id
  @request_id
end

Instance Method Details

#to_sObject



40
41
42
43
44
# File 'lib/aliyun/sts/exception.rb', line 40

def to_s
  @attrs.merge({'HTTPCode' => @http_code}).map do |k, v|
    [k, v].join(": ")
  end.join(", ")
end