diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /lib/gitlab/exceptions_app.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'lib/gitlab/exceptions_app.rb')
-rw-r--r-- | lib/gitlab/exceptions_app.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/exceptions_app.rb b/lib/gitlab/exceptions_app.rb new file mode 100644 index 00000000000..de07b788fb9 --- /dev/null +++ b/lib/gitlab/exceptions_app.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require_relative 'utils/override' + +module Gitlab + class ExceptionsApp < ActionDispatch::PublicExceptions + extend ::Gitlab::Utils::Override + + REQUEST_ID_PLACEHOLDER = '<!-- REQUEST_ID -->' + REQUEST_ID_PARAGRAPH = '<p>Request ID: <code>%s</code></p>' + + override :call + def call(env) + status, headers, body = super + + if html_rendered? && body.first&.include?(REQUEST_ID_PLACEHOLDER) + body = [insert_request_id(env, body.first)] + headers['X-GitLab-Custom-Error'] = '1' + end + + [status, headers, body] + end + + private + + override :render_html + def render_html(status) + @html_rendered = true + + super + end + + def html_rendered? + !!@html_rendered + end + + def insert_request_id(env, body) + request_id = ERB::Util.html_escape(ActionDispatch::Request.new(env).request_id) + + body.gsub(REQUEST_ID_PLACEHOLDER, REQUEST_ID_PARAGRAPH % [request_id]) + end + end +end |