Class: Common::Client::Middleware::Logging

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/common/client/middleware/logging.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, type_key) ⇒ Logging

Returns a new instance of Logging.



7
8
9
10
# File 'lib/common/client/middleware/logging.rb', line 7

def initialize(app, type_key)
  super(app)
  @type_key = type_key
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/common/client/middleware/logging.rb', line 12

def call(env)
  request_body = Base64.encode64(env.body) if env.body

  @app.call(env).on_complete do |response_env|
    PersonalInformationLog.create(
      error_class: @type_key, # TODO: error_class is probably worth renaming
      data: {
        method: env.method,
        url: env.url.to_s,
        request_body:,
        response_body: Base64.encode64(response_env.body)
      }
    )
  end
end