Exception: Aliyun::OSS::ServerError
- Includes:
- Logging
- 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.
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
Instance Method Summary collapse
-
#initialize(response) ⇒ ServerError
constructor
A new instance of ServerError.
- #to_s ⇒ Object
Methods included from Logging
#logger, set_log_file, set_log_level
Constructor Details
#initialize(response) ⇒ ServerError
Returns a new instance of ServerError.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aliyun/oss/exception.rb', line 25 def initialize(response) @http_code = response.code @attrs = {'RequestId' => get_request_id(response)} doc = Nokogiri::XML(response.body) do |config| config. |= 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_code ⇒ Object (readonly)
Returns the value of attribute error_code.
23 24 25 |
# File 'lib/aliyun/oss/exception.rb', line 23 def error_code @error_code end |
#http_code ⇒ Object (readonly)
Returns the value of attribute http_code.
23 24 25 |
# File 'lib/aliyun/oss/exception.rb', line 23 def http_code @http_code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
23 24 25 |
# File 'lib/aliyun/oss/exception.rb', line 23 def @message end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
23 24 25 |
# File 'lib/aliyun/oss/exception.rb', line 23 def request_id @request_id end |
Instance Method Details
#to_s ⇒ Object
48 49 50 51 52 |
# File 'lib/aliyun/oss/exception.rb', line 48 def to_s @attrs.merge({'HTTPCode' => @http_code}).map do |k, v| [k, v].join(": ") end.join(", ") end |