Skip to content

Commit

Permalink
Merge pull request #676 from MITLibraries/timx-197-record-not-found
Browse files Browse the repository at this point in the history
Provide message when record not found
  • Loading branch information
JPrevost authored Mar 15, 2023
2 parents 110a859 + 6737dea commit e5315ec
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def info
def record_id(id:, index:)
result = Retrieve.new.fetch(id, Timdex::OSClient, index)
result['hits']['hits'].first['_source']
rescue Elasticsearch::Transport::Transport::Errors::NotFound
rescue OpenSearch::Transport::Transport::Errors::NotFound
raise GraphQL::ExecutionError, "Record '#{id}' not found"
end

Expand Down
16 changes: 16 additions & 0 deletions test/controllers/graphql_controller_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ def setup
end
end

test 'graphqlv2 retrieve with not found recordid' do
VCR.use_cassette('graphql v2 retrieve not found') do
post '/graphql', params: { query: '{
recordId(id: "totallylegitrecordid") {
timdexRecordId
title
}
}' }
assert_equal(200, response.status)
json = JSON.parse(response.body)
assert_nil(json['data'])
assert_equal("Record 'totallylegitrecordid' not found", json['errors'].first['message'])
end
end


test 'graphqlv2 holding location is not required' do
VCR.use_cassette('graphql v2 location') do
post '/graphql', params: { query: '{
Expand Down
76 changes: 76 additions & 0 deletions test/vcr_cassettes/graphql_v2_retrieve_not_found.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5315ec

Please sign in to comment.