Skip to content

Commit

Permalink
Provide message when record not found
Browse files Browse the repository at this point in the history
Why are these changes being introduced:

* when a recordId query was run but no record was found, the application
  through a 500 error
* expected behavior would be to return a message to the user that the
  record they requested was not found

Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/TIMX-197

How does this address that need:

* This fixes a copy/paste error where we were looking for an
  ElasticSearch Not Found error rather than an OpenSearch Not Found
  error in the GraphQL for v2 logic
  • Loading branch information
JPrevost committed Mar 15, 2023
1 parent 110a859 commit 6737dea
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 6737dea

Please sign in to comment.