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