Skip to content

Commit

Permalink
handle failed queries for affiliations. datacite/datacite#898
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 13, 2019
1 parent 817f747 commit 81e187d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def facet_by_affiliation(arr)
# generate hash with id and name for each provider in facet

ids = arr.map { |hsh| "\"#{hsh["key"]}\"" }.join(" ")
affiliations = Organization.query(ids, size: 1000)[:data]
affiliations = Organization.query(ids, size: 1000)[:data] || []

arr.map do |hsh|
{ "id" => hsh["key"],
Expand Down
4 changes: 2 additions & 2 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def self.query(query, options={})

response = Maremma.get(url, host: true)

return [] if response.status != 200
return {} if response.status != 200

data = Array.wrap(response.body.dig("data", "items")).map do |message|
parse_message(id: message["id"], message: message)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@
organizations = Organization.query(query)
expect(organizations[:data]).to be_empty
end

it "status code not 200" do
url = "https://api.ror.org/organizations?query=lincoln%20university"
stub = stub_request(:get, url).and_return(status: [408])

query = "lincoln university"
organizations = Organization.query(query)
expect(organizations).to be_empty
expect(stub).to have_been_requested
end
end
end

0 comments on commit 81e187d

Please sign in to comment.