Class: Gitlab::GrapeLogging::Loggers::ExceptionLogger

Inherits:
GrapeLogging::Loggers::Base
  • Object
show all
Defined in:
lib/gitlab/grape_logging/loggers/exception_logger.rb

Instance Method Summary collapse

Instance Method Details

#parameters(request, response_body) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/grape_logging/loggers/exception_logger.rb', line 7

def parameters(request, response_body)
  data = {}
  data[:api_error] = format_body(response_body) if bad_request?(request)

  # grape-logging attempts to pass the logger the exception
  # (https://github.com/aserafin/grape_logging/blob/v1.7.0/lib/grape_logging/middleware/request_logger.rb#L63),
  # but it appears that the rescue_all in api.rb takes
  # precedence so the logger never sees it. We need to
  # store and retrieve the exception from the environment.
  exception = request.env[::API::Helpers::API_EXCEPTION_ENV]

  return data unless exception.is_a?(Exception)

  Gitlab::ExceptionLogFormatter.format!(exception, data)

  data
end