Welcome to mirror list, hosted at ThFree Co, Russian Federation.

exception_logger.rb « loggers « grape_logging « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 022eb15d28db4a87d78e4176f8c3089702f856df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Gitlab
  module GrapeLogging
    module Loggers
      class ExceptionLogger < ::GrapeLogging::Loggers::Base
        def parameters(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 {} unless exception.is_a?(Exception)

          data = {
            exception: {
              class: exception.class.to_s,
              message: exception.message
            }
          }

          if exception.backtrace
            data[:exception][:backtrace] = Gitlab::Profiler.clean_backtrace(exception.backtrace)
          end

          data
        end
      end
    end
  end
end