Skip to content

Commit

Permalink
proper error message for dois not in crossref index. #303
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 6, 2019
1 parent 0f41036 commit 7f81cba
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ GEM
latex-decode (~> 0.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bolognese (1.2.9)
bolognese (1.2.11)
activesupport (>= 4.2.5, < 6)
benchmark_methods (~> 0.7)
bibtex-ruby (~> 4.1)
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ def safe_params
p[:schemaVersion] = METADATA_FORMATS.include?(meta["from"]) ? LAST_SCHEMA_VERSION : p[:schemaVersion]
xml = meta["string"]

# if metadata for DOIs from other registration agencies are not found
fail ActiveRecord::RecordNotFound if meta["state"] == "not_found"

read_attrs = [p[:creators], p[:contributors], p[:titles], p[:publisher],
p[:publicationYear], p[:types], p[:descriptions], p[:container], p[:sizes],
p[:formats], p[:version], p[:language], p[:dates], p[:identifiers],
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/crossref_doi_by_id_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def perform(id, options={})
logger.info "DOI #{doi} record created."
elsif response.status == 200
logger.info "DOI #{doi} record updated."
elsif response.status == 404
logger.info "[Error parsing #{ra} DOI #{doi}]: not found."
else
logger.error "[Error parsing #{ra} DOI #{doi}]: " + response.body["errors"].inspect
end
Expand Down

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

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

34 changes: 34 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,40 @@
end
end

context 'crossref url not found', vcr: true do
let(:provider) { create(:provider, name: "Crossref", symbol: "CROSSREF", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "Crossref Citations", symbol: "CROSSREF.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.3389/fmicb.2019.01425") }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"xml" => xml,
"source" => "test",
"event" => "publish"
},
"relationships" => {
"client" => {
"data" => {
"type" => "clients",
"id" => client.symbol.downcase
}
}
}
}
}
end

it 'not found on updating the record' do
patch "/dois/10.3389/fmicb.2019.01425", valid_attributes, headers

expect(last_response.status).to eq(404)
expect(json['errors']).to eq([{"status"=>"404", "title"=>"The resource you are looking for doesn't exist."}])
end
end

context 'medra url', vcr: true do
let(:provider) { create(:provider, name: "mEDRA", symbol: "MEDRA", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "mEDRA Citations", symbol: "MEDRA.CITATIONS") }
Expand Down

0 comments on commit 7f81cba

Please sign in to comment.