diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-08-23 18:42:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-23 18:42:20 -0400 |
commit | b204d167c5cfebd59f771d406178e371811ac43a (patch) | |
tree | f821c5251b80d84a5024a8b49bbe1c69e1338a31 /activestorage/lib | |
parent | de6a200f82a3de399fa685d583503bc88dbc5e9f (diff) | |
parent | 6acf2fa363cee293286578b83646af4015a140df (diff) | |
download | rails-b204d167c5cfebd59f771d406178e371811ac43a.tar.gz rails-b204d167c5cfebd59f771d406178e371811ac43a.tar.bz2 rails-b204d167c5cfebd59f771d406178e371811ac43a.zip |
Merge pull request #33667 from cbothner/azure-service-swallowing-all-errors
Handle only specifically relevant Azure HTTPErrors in ActiveStorage::Service::AzureStorageService
Diffstat (limited to 'activestorage/lib')
-rw-r--r-- | activestorage/lib/active_storage/service/azure_storage_service.rb | 20 |
1 files changed, 13 insertions, 7 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..4fde35bdeb 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 @@ -128,8 +127,12 @@ module ActiveStorage def blob_for(key) blobs.get_blob_properties(container, key) - rescue Azure::Core::Http::HTTPError - false + rescue Azure::Core::Http::HTTPError => e + if e.type == "BlobNotFound" + false + else + raise + end end def format_expiry(expires_in) @@ -155,8 +158,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 |