Class: FlowcommerceSpree::LoggingHttpClient
- Inherits:
-
Io::Flow::V0::HttpClient::DefaultHttpHandlerInstance
- Object
- Io::Flow::V0::HttpClient::DefaultHttpHandlerInstance
- FlowcommerceSpree::LoggingHttpClient
- Defined in:
- lib/flowcommerce_spree/logging_http_client.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #execute(request) ⇒ Object
-
#initialize(base_uri, logger: FlowcommerceSpree.logger) ⇒ LoggingHttpClient
constructor
A new instance of LoggingHttpClient.
Constructor Details
#initialize(base_uri, logger: FlowcommerceSpree.logger) ⇒ LoggingHttpClient
Returns a new instance of LoggingHttpClient.
7 8 9 10 |
# File 'lib/flowcommerce_spree/logging_http_client.rb', line 7 def initialize(base_uri, logger: FlowcommerceSpree.logger) super(base_uri) @logger = logger end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/flowcommerce_spree/logging_http_client.rb', line 5 def error @error end |
Instance Method Details
#execute(request) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flowcommerce_spree/logging_http_client.rb', line 12 def execute(request) # original_open = client.open_timeout # original_read = client.read_timeout start_time = Time.now.utc.round(10) # Contrived example to show how client settings can be adjusted # if request.path.start_with?('/organizations') # client.open_timeout = 60 # client.read_timeout = 60 # end begin response = super rescue Io::Flow::V0::HttpClient::ServerError => e @error = { error: Oj.load(e.body), code: e.code, status: e.details } raise exception_to_raise(e), @error.dig(:error, 'messages') ensure # client.open_timeout = original_open # client.read_timeout = original_read log_request(request, response, start_time) end end |