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`.
This commit is contained in:
Cameron Bothner 2018-08-18 14:03:52 -04:00
parent 5cd2d07bdc
commit 22efb2ec49
3 changed files with 16 additions and 0 deletions

@ -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

@ -13,6 +13,8 @@ def show
else
head :not_found
end
rescue Errno::ENOENT
head :not_found
end
def update

@ -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!"