diff options
author | syasonik <syasonik@gitlab.com> | 2019-06-06 17:49:40 +0100 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-06-06 23:05:19 +0100 |
commit | ecdc50b198796275b5f0862c5cdb0dca5aac1213 (patch) | |
tree | fa7313c2256ef693252e403fed7949c7138dd77b /lib | |
parent | cd94500a42dcdf381b3c67daa74e6e95b83c90b5 (diff) | |
download | gitlab-ce-ecdc50b198796275b5f0862c5cdb0dca5aac1213.tar.gz |
Switch errors to inherit from a base classprom-api-1
Error classes associated with individual stages of
dashboard processing tend to have very long names.
As dashboard post-processing includes more steps,
we will likely need to handle more error cases.
Refactoring to have all errors inherit from a specific
base class will help accommodate this and keep the code
more readable.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/dashboard/base_service.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/base_stage.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/lib/gitlab/metrics/dashboard/base_service.rb b/lib/gitlab/metrics/dashboard/base_service.rb index ce6ecf933a1..4664aee71f6 100644 --- a/lib/gitlab/metrics/dashboard/base_service.rb +++ b/lib/gitlab/metrics/dashboard/base_service.rb @@ -6,14 +6,13 @@ module Gitlab module Metrics module Dashboard class BaseService < ::BaseService - DASHBOARD_LAYOUT_ERROR = Gitlab::Metrics::Dashboard::Stages::BaseStage::DashboardLayoutError - MISSING_QUERY_ERROR = Gitlab::Metrics::Dashboard::Stages::EndpointInserter::MissingQueryError + PROCESSING_ERROR = Gitlab::Metrics::Dashboard::Stages::BaseStage::DashboardProcessingError def get_dashboard return error("#{dashboard_path} could not be found.", :not_found) unless path_available? success(dashboard: process_dashboard) - rescue DASHBOARD_LAYOUT_ERROR, MISSING_QUERY_ERROR => e + rescue PROCESSING_ERROR => e error(e.message, :unprocessable_entity) end diff --git a/lib/gitlab/metrics/dashboard/stages/base_stage.rb b/lib/gitlab/metrics/dashboard/stages/base_stage.rb index a6d1f974556..0db7b176e8d 100644 --- a/lib/gitlab/metrics/dashboard/stages/base_stage.rb +++ b/lib/gitlab/metrics/dashboard/stages/base_stage.rb @@ -5,7 +5,8 @@ module Gitlab module Dashboard module Stages class BaseStage - DashboardLayoutError = Class.new(StandardError) + DashboardProcessingError = Class.new(StandardError) + LayoutError = Class.new(DashboardProcessingError) DEFAULT_PANEL_TYPE = 'area-chart' @@ -25,15 +26,15 @@ module Gitlab protected def missing_panel_groups! - raise DashboardLayoutError.new('Top-level key :panel_groups must be an array') + raise LayoutError.new('Top-level key :panel_groups must be an array') end def missing_panels! - raise DashboardLayoutError.new('Each "panel_group" must define an array :panels') + raise LayoutError.new('Each "panel_group" must define an array :panels') end def missing_metrics! - raise DashboardLayoutError.new('Each "panel" must define an array :metrics') + raise LayoutError.new('Each "panel" must define an array :metrics') end def for_metrics diff --git a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb index 565fcde5c2c..2a959854be0 100644 --- a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb +++ b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb @@ -5,7 +5,7 @@ module Gitlab module Dashboard module Stages class EndpointInserter < BaseStage - MissingQueryError = Class.new(StandardError) + MissingQueryError = Class.new(DashboardProcessingError) def transform! for_metrics do |metric| @@ -31,7 +31,7 @@ module Gitlab def query_for_metric(metric) query = metric[query_type(metric)] - raise MissingQueryError.new('Missing required metric key: one of :query or :query_range') unless query + raise MissingQueryError.new('Each "metric" must define one of :query or :query_range') unless query query end |