From 63583872aa1570ae3b695d5c1684b48873c7ccf0 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 10 Nov 2023 15:51:20 -0600 Subject: [PATCH] Handle missing file in cocina --- app/models/stacks_rights.rb | 2 +- spec/requests/file_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/stacks_rights.rb b/app/models/stacks_rights.rb index b26e69de..a85ab390 100644 --- a/app/models/stacks_rights.rb +++ b/app/models/stacks_rights.rb @@ -120,7 +120,7 @@ def cocina_file def find_file public_json.dig('structural', 'contains') .lazy.flat_map { |file_set| file_set.dig('structural', 'contains') } - .find { |file| file['filename'] == file_name } || raise("File not found '#{file_name}'") + .find { |file| file['filename'] == file_name } || raise(ActionController::MissingFile, "File not found '#{file_name}'") end def public_json diff --git a/spec/requests/file_spec.rb b/spec/requests/file_spec.rb index 77dac360..367890a4 100644 --- a/spec/requests/file_spec.rb +++ b/spec/requests/file_spec.rb @@ -86,4 +86,11 @@ expect(response).to be_successful end end + + describe 'GET missing file' do + it 'returns a 400 HTTP response' do + get '/file/xf680rd3068/path/to/99999.jp2' + expect(response).to have_http_status(Settings.features.cocina ? :not_found : :forbidden) + end + end end