class Aliyun::ESS::Error
Anything you do that makes a request to OSS could result in an error. If it does, the Aliyun::OSS library will raise an exception specific to the error. All exception that are raised as a result of a request returning an error response inherit from the ResponseError
exception. So should you choose to rescue any such exception, you can simple rescue ResponseError
.
Say you go to delete a bucket, but the bucket turns out to not be empty. This results in a BucketNotEmpty error (one of the many errors listed at docs.aliyunwebservices.com/AliyunOSS/2006-03-01/ErrorCodeList.html):
begin Bucket.delete('jukebox') rescue ResponseError => error # ... end
Once you’ve captured the exception, you can extract the error message from OSS, as well as the full error response, which includes things like the HTTP response code:
error # => #<Aliyun::OSS::BucketNotEmpty The bucket you tried to delete is not empty> error.message # => "The bucket you tried to delete is not empty" error.response.code # => 409
You could use this information to redisplay the error in a way you see fit, or just to log the error and continue on.