Rails: sporadic errors Carrierwave / Excon

Using a carrier wave for our users, we get a couple of Excon errors every week from our production application. For instance:

Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>IncompleteBody</Code><Message>The request body terminated unexpectedly</Message> 

We started to wrap the boot process in the retry block, and it always works fine after another try, but I wonder if there is a better solution, because after a while it becomes cumbersome. It seems to me that these errors should be handled at a lower level. Is there a better way to deal with these problems?

Here is our production configuration:

 config.storage = :fog config.root = Dir.tmpdir config.cache_dir = 'carrierwave' config.fog_credentials = { provider: 'AWS', aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key: ENV['AWS_ACCESS_KEY'], } config.fog_directory = ENV['AWS_S3_BUCKET'] config.fog_public = false config.fog_authenticated_url_expiration = 7.days.to_i config.enable_processing = true 

And we use gem versions:

 fog (1.27.0) carrierwave (0.10.0) excon (0.43.0) 
+6
source share
1 answer

It started working again after I wrote my initializer, like this, after overcoming several problems, I think the AWS endpoints have changed:

 CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', :aws_access_key_id => ENV['S3_KEY'], :aws_secret_access_key => ENV['S3_SECRET'], :endpoint => "https://s3.amazonaws.com", :region => ENV['S3_REGION'] } config.fog_directory = ENV['S3_BUCKET'] end 

Also, I thought my region was "us-west-2" looking at my AWS administration console, but it only started working when I switched to "eu-west-1".

Later I realized that this endpoint should not be indicated; in fact, it is better to leave it in this situation. In any case, having switched to the carrier wave, as indicated by Lobati, she solved the problem.

+3
source

Source: https://habr.com/ru/post/981374/