I have created a method, which is raising the same exception in case of any error:
def fetch_aws_instances
region_name = 'us-west-2'
ec2 = Aws::EC2::Client.new(region: region_name)
describe_regions_result = ec2.describe_region
...
...
rescue Seahorse::Client::NetworkingError, Aws::Errors::MissingCredentialsError, Aws::EC2::Errors::UnauthorizedOperation => error
raise error
end
Now, I am calling this method like this:
begin
fetch_aws_instances
rescue Seahorse::Client::NetworkingError
Rails.logger.error 'Network Error: Please check whether the application instance is allowed outbound access to the Internet.'
rescue Aws::Errors::MissingCredentialsError, Aws::EC2::Errors::UnauthorizedOperation
Rails.logger.error 'Authorization Error: Please ensure IAM role is attached to the application instance.'
end
Am I calling the method in correct way, do I need to rescue all the errors or is there some better way to do it?