Class: Aliyun::OSS::Error

Inherits:
Object show all
Defined in:
lib/aliyun/oss/error.rb,
lib/aliyun/oss/response.rb

Overview

Requests whose response code is between 300 and 599 and contain an <Error></Error> in their body are wrapped in an Error::Response. This Error::Response contains an Error object which raises an exception that corresponds to the error in the response body. The exception object contains the ErrorResponse, so in all cases where a request happens, you can rescue ResponseError and have access to the ErrorResponse and its Error object which contains information about the ResponseError.

begin
  Bucket.create(..)
rescue ResponseError => exception
 exception.response
 # => <Error::Response>
 exception.response.error
 # => <Error>
end

Defined Under Namespace

Classes: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, response = nil) ⇒ Error

Returns a new instance of Error.



31
32
33
34
35
36
# File 'lib/aliyun/oss/error.rb', line 31

def initialize(error, response = nil)
  @error     = error
  @response  = response
  @container = Aliyun::OSS
  find_or_create_exception!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



59
60
61
62
63
64
65
66
# File 'lib/aliyun/oss/error.rb', line 59

def method_missing(method, *args, &block)
  # We actually want nil if the attribute is nil. So we use has_key? rather than [] + ||.
  if error.has_key?(method.to_s)
    error[method.to_s]
  else
    super
  end
end

Instance Attribute Details

#responseObject

:stopdoc:



30
31
32
# File 'lib/aliyun/oss/error.rb', line 30

def response
  @response
end

Instance Method Details

#raiseObject



38
39
40
# File 'lib/aliyun/oss/error.rb', line 38

def raise
  Kernel.raise exception.new(message, response)
end