Class: Fbe::Middleware::Formatter
- Inherits:
-
Faraday::Logging::Formatter
- Object
- Faraday::Logging::Formatter
- Fbe::Middleware::Formatter
- Defined in:
- lib/fbe/middleware/formatter.rb
Overview
Faraday logging formatter shows verbose logs for error responses only
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Zerocracy
- License
-
MIT
Instance Method Summary collapse
-
#request(http) ⇒ Object
Log HTTP request.
-
#response(http) ⇒ Object
Log HTTP response.
Instance Method Details
#request(http) ⇒ Object
Log HTTP request.
20 21 22 |
# File 'lib/fbe/middleware/formatter.rb', line 20 def request(http) @req = http end |
#response(http) ⇒ Object
Log HTTP response.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fbe/middleware/formatter.rb', line 27 def response(http) return if http.status < 400 if http.status == 403 && http.response_headers['content-type'].start_with?('application/json') warn( [ "#{@req.method.upcase} #{apply_filters(@req.url.to_s)}", '->', http.status, '/', JSON.parse(http.response_body)['message'] ].join(' ') ) return end error( [ "#{@req.method.upcase} #{apply_filters(@req.url.to_s)} HTTP/1.1", shifted(apply_filters(dump_headers(@req.request_headers))), '', shifted(apply_filters(@req.request_body)), "HTTP/1.1 #{http.status}", shifted(apply_filters(dump_headers(http.response_headers))), '', shifted(apply_filters(http.response_body)) ].join("\n") ) end |