2

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)
2
  • I've updated the post for maybe more clarity... Commented Dec 16, 2020 at 16:38
  • figured the solution and updated the question with the solution Commented Dec 16, 2020 at 17:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.