2019-10-12 21:52:04 +05:30
|
|
|
# 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
|
2019-12-04 20:38:33 +05:30
|
|
|
DashboardProcessingError = Class.new(StandardError)
|
2019-10-12 21:52:04 +05:30
|
|
|
PanelNotFoundError = Class.new(StandardError)
|
2019-12-26 22:10:19 +05:30
|
|
|
MissingIntegrationError = Class.new(StandardError)
|
2019-12-04 20:38:33 +05:30
|
|
|
LayoutError = Class.new(DashboardProcessingError)
|
|
|
|
MissingQueryError = Class.new(DashboardProcessingError)
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
NOT_FOUND_ERROR = Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
|
|
|
|
|
|
|
|
def handle_errors(error)
|
|
|
|
case error
|
2019-12-04 20:38:33 +05:30
|
|
|
when DashboardProcessingError
|
2019-10-12 21:52:04 +05:30
|
|
|
error(error.message, :unprocessable_entity)
|
|
|
|
when NOT_FOUND_ERROR
|
2020-07-28 23:09:34 +05:30
|
|
|
error(_("%{dashboard_path} could not be found.") % { dashboard_path: dashboard_path }, :not_found)
|
2019-10-12 21:52:04 +05:30
|
|
|
when PanelNotFoundError
|
|
|
|
error(error.message, :not_found)
|
2019-12-26 22:10:19 +05:30
|
|
|
when ::Grafana::Client::Error
|
|
|
|
error(error.message, :service_unavailable)
|
|
|
|
when MissingIntegrationError
|
2020-07-28 23:09:34 +05:30
|
|
|
error(_('Proxy support for this API is not available currently'), :bad_request)
|
2019-10-12 21:52:04 +05:30
|
|
|
else
|
|
|
|
raise error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def panels_not_found!(opts)
|
2021-06-08 01:23:25 +05:30
|
|
|
raise PanelNotFoundError, _("No panels matching properties %{opts}") % { opts: opts }
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|