Skip to content

Commit

Permalink
don't raise elasticsearch 504 errors. #222
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 19, 2019
1 parent 82c5f95 commit 6601bb6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def index
options[:is_collection] = true

render json: ClientSerializer.new(@clients, options).serialized_json, status: :ok
rescue Elasticsearch::Transport::Transport::Errors::GatewayTimeout => exception
head :gateway_timeout
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => exception
Raven.capture_exception(exception)

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ def index
end
format.any(:bibtex, :citeproc, :codemeta, :crosscite, :datacite, :datacite_json, :jats, :ris, :csv, :schema_org) { render request.format.to_sym => response.records.to_a }
end
rescue Elasticsearch::Transport::Transport::Errors::GatewayTimeout => exception
head :gateway_timeout
rescue 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")

render json: { "errors" => { "title" => message }}.to_json, status: :bad_request
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ def index
options[:links] = nil

render json: MemberSerializer.new(@members, options).serialized_json, status: :ok
rescue Elasticsearch::Transport::Transport::Errors::GatewayTimeout => exception
head :gateway_timeout
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => exception
# Bugsnag.notify(exception)

Raven.capture_exception(exception)
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
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/_version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Lupo
class Application
g = Git.open(Rails.root, :log => Logger.new(STDOUT))
g = Git.open(Rails.root)
begin
VERSION = g.tags.map { |t| Gem::Version.new(t.name) }.sort.last.to_s
rescue ArgumentError
Expand Down

0 comments on commit 6601bb6

Please sign in to comment.