Skip to content

Commit

Permalink
Timeout crossref requests at 2 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhallett committed Jan 19, 2022
1 parent 412704f commit 609af27
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def index
def show
url = "#{ENV['API_URL']}/dois/#{@doi}"
response = Maremma.get(url, accept: "application/vnd.datacite.datacite+json", raw: true)

if response.status == 200
@metadata = Bolognese::Metadata.new(input: response.body.fetch("data", nil), from: "datacite_json")
else
url = "https://api.crossref.org/works/#{@doi}/transform/application/vnd.crossref.unixsd+xml"
response = Maremma.get(url, accept: "text/xml", raw: true)
response = Maremma.get(url, accept: "text/xml", raw: true, timeout: 2)

if response.status == 200
string = response.body.fetch("data", nil)
string = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks).to_s if string.present?
Expand All @@ -29,7 +29,7 @@ def show
url = "https://doi.org/#{@doi}"
response = Maremma.get(url, accept: "application/vnd.citationstyles.csl+json", raw: true)
fail AbstractController::ActionNotFound if response.status != 200

string = response.body.fetch("data", nil)
@metadata = Bolognese::Metadata.new(input: string, from: "citeproc")
else
Expand Down

0 comments on commit 609af27

Please sign in to comment.