How determine level error of aws s3 sdk errors?

587 views Asked by At

Question

I'm trying to determine wether an error returned by the AWS ruby SDK is a server error or a client error.

Using gem 'aws-sdk-s3', '~> 1'.

Looking at the documentation: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Errors/ServiceError.html#code-instance_method it is specified that error level 400~>599 are returned as a ServiceError. But how to identify the subset: 500~>599?

I catch exception with the following check:

begin
  resource = Aws::S3::Resource.new(client: ...)
  bucket = resource.bucket(...)
  object = bucket.object(...).get
rescue Aws::S3::Errors::ServiceError => e
  puts 'server error' if e.<missing part> ??? 
end

I can't figure what the "missing part" is.

Solution

Aws::S3::Errors::ServiceError has a context param which itself has a http_response.

puts 'server error' if e.context.http_response[:status_code].between?(500, 599)
0

There are 0 answers