Skip to content

Commit

Permalink
handle missing value for repository service contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 10, 2020
1 parent 6d1c13e commit c2ad883
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def repositories
page_num += 1
end

logger.warn "Exporting #{clients.length} repositories."

# Get doi counts via DOIs query and combine next to clients.
response = Doi.query(nil, state: "registered,findable", page: { size: 0, number: 1 }, totals_agg: "client")

Expand Down Expand Up @@ -270,9 +272,9 @@ def repositories
accountDescription: client.description,
accountWebsite: client.url,
generalContactEmail: client.system_email,
serviceContactEmail: client.service_contact.email,
serviceContactGivenName: client.service_contact.given_name,
serviceContactFamilyName: client.service_contact.family_name,
serviceContactEmail: client.service_contact.present? ? client.service_contact.email : nil,
serviceContactGivenName: client.service_contact.present? ? client.service_contact.given_name : nil,
serviceContactFamilyName: client.service_contact.present? ? client.service_contact.family_name : nil,
created: export_date(client.created),
modified: export_date(client.updated),
deleted: client.deleted_at.present? ? export_date(client.deleted_at) : nil,
Expand All @@ -288,9 +290,9 @@ def repositories
rescue StandardError, Elasticsearch::Transport::Transport::Errors::BadRequest => exception
Raven.capture_exception(exception)

message = JSON.parse(exception.message[6..-1]).to_h.dig("error", "root_cause", 0, "reason")
# message = JSON.parse(exception.message[6..-1]).to_h.dig("error", "root_cause", 0, "reason")

render json: { "errors" => { "title" => message }}.to_json, status: :bad_request
render json: { "errors" => { "title" => exception.message }}.to_json, status: :bad_request
end
end

Expand Down

0 comments on commit c2ad883

Please sign in to comment.