Commit 332275b7 authored by Stan Hu's avatar Stan Hu

Simplify error message handling in Projects::CreateService

There's no need to add a redundant message to the errors if the
model is invalid. This cleans up the message as well for the importer.
parent 3a722ff5
...@@ -27,11 +27,6 @@ class Import::BaseController < ApplicationController ...@@ -27,11 +27,6 @@ class Import::BaseController < ApplicationController
end end
def project_save_error(project) def project_save_error(project)
# Projects::CreateService will set base message if unable to save project.errors.full_messages.join(', ')
if project.errors[:base].present?
project.errors[:base].last
else
project.errors.full_messages.join(', ')
end
end end
end end
...@@ -63,6 +63,7 @@ module Projects ...@@ -63,6 +63,7 @@ module Projects
message = "Unable to save #{e.record.type}: #{e.record.errors.full_messages.join(", ")} " message = "Unable to save #{e.record.type}: #{e.record.errors.full_messages.join(", ")} "
fail(error: message) fail(error: message)
rescue => e rescue => e
@project.errors.add(:base, e.message) if @project
fail(error: e.message) fail(error: e.message)
end end
...@@ -141,7 +142,6 @@ module Projects ...@@ -141,7 +142,6 @@ module Projects
Rails.logger.error(log_message) Rails.logger.error(log_message)
if @project if @project
@project.errors.add(:base, message)
@project.mark_import_as_failed(message) if @project.persisted? && @project.import? @project.mark_import_as_failed(message) if @project.persisted? && @project.import?
end end
......
...@@ -119,21 +119,6 @@ shared_examples 'a GitHub-ish import controller: POST create' do ...@@ -119,21 +119,6 @@ shared_examples 'a GitHub-ish import controller: POST create' do
end end
it 'returns 422 response with the base error when the project could not be imported' do it 'returns 422 response with the base error when the project could not be imported' do
project = build(:project)
error_message = 'This is an error'
project.errors.add(:base, error_message)
allow(Gitlab::LegacyGithubImport::ProjectCreator)
.to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider)
.and_return(double(execute: project))
post :create, format: :json
expect(response).to have_gitlab_http_status(422)
expect(json_response['errors']).to eq(error_message)
end
it 'returns 422 response with a combined error when the project could not be imported' do
project = build(:project) project = build(:project)
project.errors.add(:name, 'is invalid') project.errors.add(:name, 'is invalid')
project.errors.add(:path, 'is old') project.errors.add(:path, 'is old')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment