Skip to content

Swallow fatal log when ignore is specified #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def perform_request(method, path, params={}, body=nil, &block)
if response.status.to_i >= 300
__log method, path, params, body, url, response, nil, 'N/A', duration if logger
__trace method, path, params, body, url, response, nil, 'N/A', duration if tracer
__log_failed response if logger

# Swallow the exception when the `ignore` parameter matches response status
# Swallow the exception and log when the `ignore` parameter matches response status
__log_failed response if logger && !ignore.include?(response.status.to_i)
__raise_transport_error response unless ignore.include?(response.status.to_i)
end

Expand Down
13 changes: 12 additions & 1 deletion elasticsearch-transport/test/unit/transport_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def initialize(*); end
@transport.perform_request('GET', '/') {Elasticsearch::Transport::Transport::Response.new 200, '{"foo":"bar"}' }
end

should "log a failed Elasticsearch request" do
should "log a failed Elasticsearch request as fatal" do
@block = Proc.new { |c, u| puts "ERROR" }
@block.expects(:call).returns(Elasticsearch::Transport::Transport::Response.new 500, 'ERROR')

Expand All @@ -432,6 +432,17 @@ def initialize(*); end
end
end unless RUBY_1_8

should "not log a failed Elasticsearch request as fatal" do
@block = Proc.new { |c, u| puts "ERROR" }
@block.expects(:call).returns(Elasticsearch::Transport::Transport::Response.new 500, 'ERROR')

@transport.expects(:__log).twice
@transport.logger.expects(:fatal).never

# No `BadRequest` error
@transport.perform_request('POST', '_search', :ignore => 500, &@block)
end unless RUBY_1_8

should "log and re-raise a Ruby exception" do
@block = Proc.new { |c, u| puts "ERROR" }
@block.expects(:call).raises(Exception)
Expand Down