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

errors.rb « dashboard « metrics « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d41bd2c43c7cadb0bc29b49a18f1e2e19b791e32 (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
# frozen_string_literal: true

# Central point for managing errors from within the metrics
# dashboard module. Handles errors from dashboard retrieval
# and processing steps, as well as defines shared error classes.
module Gitlab
  module Metrics
    module Dashboard
      module Errors
        DashboardProcessingError = Class.new(StandardError)
        PanelNotFoundError = Class.new(StandardError)
        LayoutError = Class.new(DashboardProcessingError)
        MissingQueryError = Class.new(DashboardProcessingError)

        NOT_FOUND_ERROR = Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError

        def handle_errors(error)
          case error
          when DashboardProcessingError
            error(error.message, :unprocessable_entity)
          when NOT_FOUND_ERROR
            error("#{dashboard_path} could not be found.", :not_found)
          when PanelNotFoundError
            error(error.message, :not_found)
          else
            raise error
          end
        end

        def panels_not_found!(opts)
          raise PanelNotFoundError.new("No panels matching properties #{opts}")
        end
      end
    end
  end
end