From 22efb2ec49087827ca1cb28a8bad9f016800c591 Mon Sep 17 00:00:00 2001 From: Cameron Bothner Date: Sat, 18 Aug 2018 14:03:52 -0400 Subject: Respond with 404 in ActiveStorage::DiskController#show when file missing `ActiveStorage::DiskController#show` generates a 404 Not Found response when the requested file is missing from the disk service. It previously raised `Errno::ENOENT`. --- activestorage/CHANGELOG.md | 6 ++++++ activestorage/app/controllers/active_storage/disk_controller.rb | 2 ++ activestorage/test/controllers/disk_controller_test.rb | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md index 8e11146121..b592f79ca6 100644 --- a/activestorage/CHANGELOG.md +++ b/activestorage/CHANGELOG.md @@ -1,3 +1,9 @@ +* `ActiveStorage::DiskController#show` generates a 404 Not Found response when + the requested file is missing from the disk service. It previously raised + `Errno::ENOENT`. + + *Cameron Bothner* + * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise `ActiveStorage::FileNotFoundError` when the corresponding file is missing from the storage service. Services translate service-specific missing object diff --git a/activestorage/app/controllers/active_storage/disk_controller.rb b/activestorage/app/controllers/active_storage/disk_controller.rb index 75cc11d6ff..7bd641ab9a 100644 --- a/activestorage/app/controllers/active_storage/disk_controller.rb +++ b/activestorage/app/controllers/active_storage/disk_controller.rb @@ -13,6 +13,8 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController else head :not_found end + rescue Errno::ENOENT + head :not_found end def update diff --git a/activestorage/test/controllers/disk_controller_test.rb b/activestorage/test/controllers/disk_controller_test.rb index c053052f6f..4bc61d13f3 100644 --- a/activestorage/test/controllers/disk_controller_test.rb +++ b/activestorage/test/controllers/disk_controller_test.rb @@ -31,6 +31,14 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest assert_equal " worl", response.body end + test "showing blob that does not exist" do + blob = create_blob + blob.delete + + get blob.service_url + assert_response :not_found + end + test "directly uploading blob with integrity" do data = "Something else entirely!" -- cgit v1.2.3