Skip to content
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

Failing test: Logging headers & errors fails when ConnectionFailed is raised #1512

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/faraday/logging/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def filter(filter_word, filter_replacement)
private

def dump_headers(headers)
return if headers.nil?

headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
end

Expand Down
10 changes: 10 additions & 0 deletions spec/faraday/response/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
stubs.get('/filtered_headers') { [200, { 'Content-Type' => 'text/html' }, 'headers response'] }
stubs.get('/filtered_params') { [200, { 'Content-Type' => 'text/html' }, 'params response'] }
stubs.get('/filtered_url') { [200, { 'Content-Type' => 'text/html' }, 'url response'] }
stubs.get('/connection_failed') { raise Faraday::ConnectionFailed, 'Failed to open TCP connection' }
end
end
end
Expand Down Expand Up @@ -216,6 +217,15 @@ def response(_env)
end
end

context 'when logging headers and errors' do
let(:logger_options) { { headers: true, errors: true } }

it 'logs error message' do
expect { conn.get '/connection_failed' }.to raise_error(Faraday::ConnectionFailed)
expect(string_io.string).to match(%(Failed to open TCP connection))
end
end

context 'when using log_level' do
let(:logger_options) { { bodies: true, log_level: :debug } }

Expand Down