summaryrefslogtreecommitdiff
path: root/lib/gitlab/metrics/dashboard/errors.rb
diff options
context:
space:
mode:
authorSarah Yasonik <syasonik@gitlab.com>2019-08-07 16:17:35 +0000
committerSean McGivern <sean@gitlab.com>2019-08-07 16:17:35 +0000
commitbf918b68f643266e91a9308cbc64a8304c647f17 (patch)
treeddface6092de44fafe2e0929158fc65d92766f47 /lib/gitlab/metrics/dashboard/errors.rb
parentd8966abd20c860d2f30141f3647f2b81f70b683d (diff)
downloadgitlab-ce-bf918b68f643266e91a9308cbc64a8304c647f17.tar.gz
Support dashboard params for metrics dashboard
https://gitlab.com/gitlab-org/gitlab-ce/issues/62971 Adds support to EnvironmentsController#metrics_dashboard for the following params: group, title, y_label These params are used to uniquely identify a panel on the metrics dashboard. Metrics are stored in several places, so this adds utilities to find a specific panel from the database or filesystem depending on the metric specified. Also moves some shared utilities into separate classes, notably default values and errors.
Diffstat (limited to 'lib/gitlab/metrics/dashboard/errors.rb')
-rw-r--r--lib/gitlab/metrics/dashboard/errors.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/gitlab/metrics/dashboard/errors.rb b/lib/gitlab/metrics/dashboard/errors.rb
new file mode 100644
index 00000000000..1739a4e6738
--- /dev/null
+++ b/lib/gitlab/metrics/dashboard/errors.rb
@@ -0,0 +1,34 @@
+# 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
+ PanelNotFoundError = Class.new(StandardError)
+
+ PROCESSING_ERROR = Gitlab::Metrics::Dashboard::Stages::BaseStage::DashboardProcessingError
+ NOT_FOUND_ERROR = Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
+
+ def handle_errors(error)
+ case error
+ when PROCESSING_ERROR
+ 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