aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage
diff options
context:
space:
mode:
authorCameron Bothner <cameronbothner@gmail.com>2018-08-23 23:36:43 -0400
committerCameron Bothner <cameronbothner@gmail.com>2018-08-23 23:36:43 -0400
commitaae56c35290da2a6251b773b3f93845e21791823 (patch)
tree7cc21e735b4bc2845228f084528fc1b66531ab5d /activestorage/lib/active_storage
parent3868648cae36fd64741135e3d33d7055e925879b (diff)
downloadrails-aae56c35290da2a6251b773b3f93845e21791823.tar.gz
rails-aae56c35290da2a6251b773b3f93845e21791823.tar.bz2
rails-aae56c35290da2a6251b773b3f93845e21791823.zip
Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything: checksum mismatch, missing object, network unavailable, and many more. (https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError). Rescuing that class obscures all sorts of configuration errors. We should check the type of error in those rescue blocks, and reraise when needed.
Diffstat (limited to 'activestorage/lib/active_storage')
-rw-r--r--activestorage/lib/active_storage/service/azure_storage_service.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/activestorage/lib/active_storage/service/azure_storage_service.rb b/activestorage/lib/active_storage/service/azure_storage_service.rb
index 66aabc1f9f..8de3889cb5 100644
--- a/activestorage/lib/active_storage/service/azure_storage_service.rb
+++ b/activestorage/lib/active_storage/service/azure_storage_service.rb
@@ -19,10 +19,8 @@ module ActiveStorage
def upload(key, io, checksum: nil)
instrument :upload, key: key, checksum: checksum do
- begin
+ handle_errors do
blobs.create_block_blob(container, key, IO.try_convert(io) || io, content_md5: checksum)
- rescue Azure::Core::Http::HTTPError
- raise ActiveStorage::IntegrityError
end
end
end
@@ -55,7 +53,8 @@ module ActiveStorage
instrument :delete, key: key do
begin
blobs.delete_blob(container, key)
- rescue Azure::Core::Http::HTTPError
+ rescue Azure::Core::Http::HTTPError => e
+ raise unless e.type == "BlobNotFound"
# Ignore files already deleted
end
end
@@ -155,8 +154,11 @@ module ActiveStorage
def handle_errors
yield
rescue Azure::Core::Http::HTTPError => e
- if e.type == "BlobNotFound"
+ case e.type
+ when "BlobNotFound"
raise ActiveStorage::FileNotFoundError
+ when "Md5Mismatch"
+ raise ActiveStorage::IntegrityError
else
raise
end