Class: Aliyun::ESS::Error
- Inherits:
-
Object
- Object
- Aliyun::ESS::Error
- Defined in:
- lib/aliyun/ess/error.rb,
lib/aliyun/ess/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
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#response ⇒ Object
:stopdoc:.
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(error, response = nil) ⇒ Error
constructor
A new instance of Error.
- #raise ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
73 74 75 76 77 78 79 80 |
# File 'lib/aliyun/ess/error.rb', line 73 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
#container ⇒ Object (readonly)
Returns the value of attribute container.
31 32 33 |
# File 'lib/aliyun/ess/error.rb', line 31 def container @container end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
31 32 33 |
# File 'lib/aliyun/ess/error.rb', line 31 def error @error end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
31 32 33 |
# File 'lib/aliyun/ess/error.rb', line 31 def exception @exception end |
#response ⇒ Object
:stopdoc:
30 31 32 |
# File 'lib/aliyun/ess/error.rb', line 30 def response @response end |
Instance Method Details
#code ⇒ Object
44 45 46 |
# File 'lib/aliyun/ess/error.rb', line 44 def code @code ||= error['code'].sub('.', '::') end |
#raise ⇒ Object
40 41 42 |
# File 'lib/aliyun/ess/error.rb', line 40 def raise Kernel.raise exception.new(, response) end |