Skip to content

Commit

Permalink
Fix: Logging headers & errors fails when ConnectionFailed is raised (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eikes committed Jun 28, 2023
1 parent be98e8e commit 990799a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 990799a

Please sign in to comment.