diff options
author | rpereira2 <rpereira@gitlab.com> | 2019-02-12 14:17:51 +0530 |
---|---|---|
committer | rpereira2 <rpereira@gitlab.com> | 2019-02-12 14:17:51 +0530 |
commit | 6036dab4c3131869bae8aa7aa83c5cbf6165e40c (patch) | |
tree | b0a70843066e83bfe503d40b3a5eaef4f29b2071 | |
parent | 46319aa771de9e3199d4f49f1c35aed18071af6c (diff) | |
download | gitlab-ce-57358-better-error-messages.tar.gz |
Improve error messages in operations settings57358-better-error-messages
-rw-r--r-- | app/models/error_tracking/project_error_tracking_setting.rb | 14 | ||||
-rw-r--r-- | app/services/projects/operations/update_service.rb | 37 |
2 files changed, 36 insertions, 15 deletions
diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb index a7dbff8f186..47cf35511e9 100644 --- a/app/models/error_tracking/project_error_tracking_setting.rb +++ b/app/models/error_tracking/project_error_tracking_setting.rb @@ -10,11 +10,9 @@ module ErrorTracking validates :api_url, length: { maximum: 255 }, public_url: true, url: { enforce_sanitization: true, ascii_only: true }, allow_nil: true - validates :api_url, presence: true, if: :enabled - validate :validate_api_url_path, if: :enabled - validates :token, presence: true, if: :enabled + validate :validate_api_url_token_presence, if: :enabled attr_encrypted :token, mode: :per_attribute_iv, @@ -120,6 +118,16 @@ module ErrorTracking @slug_match[capture] end + def validate_api_url_token_presence + if self.api_url.blank? + errors.add(:base, 'Sentry API URL is a required field.') + end + + if self.token.blank? + errors.add(:base, 'Sentry API Auth Token is a required field.') + end + end + def validate_api_url_path return if api_url.blank? diff --git a/app/services/projects/operations/update_service.rb b/app/services/projects/operations/update_service.rb index aedf79c86d7..1341185d132 100644 --- a/app/services/projects/operations/update_service.rb +++ b/app/services/projects/operations/update_service.rb @@ -4,15 +4,30 @@ module Projects module Operations class UpdateService < BaseService def execute - Projects::UpdateService - .new(project, current_user, project_update_params) - .execute + setting = project.error_tracking_setting + + result = if setting.nil? + project.create_error_tracking_setting( + error_tracking_params.merge(project_id: project.id) + ) + else + setting.update(error_tracking_params) + end + + if result + success + else + update_failed! + end end private - def project_update_params - error_tracking_params + def update_failed! + model_errors = project.error_tracking_setting&.errors&.full_messages + error_message = model_errors.presence || 'Error tracking settings could not be updated!' + + error(error_message) end def error_tracking_params @@ -26,13 +41,11 @@ module Projects ) { - error_tracking_setting_attributes: { - api_url: api_url, - token: settings[:token], - enabled: settings[:enabled], - project_name: settings.dig(:project, :name), - organization_name: settings.dig(:project, :organization_name) - } + api_url: api_url, + token: settings[:token], + enabled: settings[:enabled], + project_name: settings.dig(:project, :name), + organization_name: settings.dig(:project, :organization_name) } end end |