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

error_handler.rb « puma « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4efc4866431eae2a8380e2e4847e9b67f425513c (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
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module Gitlab
  module Puma
    class ErrorHandler
      PROD_ERROR_MESSAGE = "An error has occurred and reported in the system's low-level error handler."
      DEV_ERROR_MESSAGE = <<~MSG
        Server Error: An error has been caught by Puma's low-level error handler.
        Read the Puma section of the troubleshooting docs for next steps - https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/troubleshooting/index.md#puma.
      MSG

      def initialize(is_production)
        @is_production = is_production
      end

      def execute(ex, env, status_code)
        # Puma v6.4.0 added the status_code argument in
        # https://github.com/puma/puma/pull/3094
        status_code ||= 500

        if Raven.configuration.capture_allowed?
          Raven.capture_exception(ex, tags: { handler: 'puma_low_level' },
            extra: { puma_env: env, status_code: status_code })
        end

        # note the below is just a Rack response
        [status_code, {}, message]
      end

      private

      def message
        if @is_production
          PROD_ERROR_MESSAGE
        else
          DEV_ERROR_MESSAGE
        end
      end
    end
  end
end