diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-11 15:06:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-11 15:06:42 +0000 |
commit | 7071f9bf3e131a7a668922ee450da529f1866b6f (patch) | |
tree | 590371b44d47d428f2826b600d7fab4f10520051 /lib/gitlab | |
parent | 16bd8409bcb61d2331227d1df539c40683b6bda3 (diff) | |
download | gitlab-ce-7071f9bf3e131a7a668922ee450da529f1866b6f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/grape_logging/loggers/exception_logger.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/loggers/exception_logger.rb b/lib/gitlab/grape_logging/loggers/exception_logger.rb new file mode 100644 index 00000000000..022eb15d28d --- /dev/null +++ b/lib/gitlab/grape_logging/loggers/exception_logger.rb @@ -0,0 +1,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 |