sul-dlss / sul_pub

SUL system for harvest and managing publications for Stanford CAP, with controlled API access.
http://cap.stanford.edu
Other
8 stars 3 forks source link

WoS Rest Links Client fails when no identifiers returned #1658

Closed peetucket closed 9 months ago

peetucket commented 9 months ago

See https://app.honeybadger.io/projects/50046/faults/101491188

author=Author.find(170880)
wos_uids = author.publications.map(&:wos_uid).compact.delete_if{|wos_uid| wos_uid.start_with?('MEDLINE:')}
results = WebOfScience.links_client.links(wos_uids)
/opt/app/pub/sul-pub/releases/20231018113244/lib/clarivate/rest_links_client.rb:75:in `dig': String does not have #dig method (TypeError)

        record.dig('dynamic_data', 'cluster_related', 'identifiers', 'identifier')
Let's figure out which WOS_UID is the problem:

wos_uids.each do |wos_uid|
     puts "#{wos_uid} : #{WebOfScience.links_client.links([wos_uid])}"
  rescue StandardError => e
   puts "#{wos_uid} : #{e.message}"
end;nil

Found it:

... WOS:A1978ES84600010 : {"WOS:A1978ES84600010"=>{}} WOS:A1975W192600011 : String does not have #dig method WOS:000373762400034 : {"WOS:000373762400034"=>{"doi"=>"10.1073/pnas.1524806113", "pmid"=>"27035977"}} ...

peetucket commented 9 months ago

Issue is that the response in the client can have a blank identifiers block like this:

{"identifiers"=>""}

instead of something like this:

{"identifiers"=> {"identifier"=>[{"type"=>"issn", "value"=>"0027-8424"}, {"type"=>"eissn", "value"=>"1091-6490"}, {"type"=>"doi", "value"=>"10.1073/pnas.1524806113"}, {"type"=>"pmid", "value"=>"MEDLINE:27035977"}]}}

which leads to a problem trying to dig into the blank block here: https://github.com/sul-dlss/sul_pub/blob/main/lib/clarivate/rest_links_client.rb#L75