Exception: Aliyun::OSS::ServerError

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

Overview

ServerError represents exceptions from the OSS 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 OSS request id.

Direct Known Subclasses

CallbackError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ServerError

Returns a new instance of ServerError.



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

def initialize(response)
  @http_code = response.code
  @attrs = {'RequestId' => get_request_id(response)}

  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.



16
17
18
# File 'lib/aliyun/oss/exception.rb', line 16

def error_code
  @error_code
end

#http_codeObject (readonly)

Returns the value of attribute http_code.



16
17
18
# File 'lib/aliyun/oss/exception.rb', line 16

def http_code
  @http_code
end

#messageObject (readonly)

Returns the value of attribute message.



16
17
18
# File 'lib/aliyun/oss/exception.rb', line 16

def message
  @message
end

#request_idObject (readonly)

Returns the value of attribute request_id.



16
17
18
# File 'lib/aliyun/oss/exception.rb', line 16

def request_id
  @request_id
end

Instance Method Details

#to_sObject



42
43
44
45
46
# File 'lib/aliyun/oss/exception.rb', line 42

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