Skip to content

Commit

Permalink
Handle missing file in cocina
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 10, 2023
1 parent 8ed1857 commit 6358387
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/stacks_rights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/requests/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6358387

Please sign in to comment.