diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-06 08:34:06 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-06 11:40:55 +0300 |
commit | 3a722ff53fe86ce6194f81ade810196f4f8e870c (patch) | |
tree | 86e7e1b0f8ff5baf148f8f3d03314f942ed0465d /app/controllers | |
parent | af07c490b2a32ed4c88e387d1133e7882f79abc5 (diff) |
Show a more helpful error for import status
Importing a project from GitHub for a project namespace that already exists
would show an unhelpful error, "An error occurred while importing project."
We now add the base message from Projects::CreateService when this fails.
Closes #47365
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/import/base_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/import/bitbucket_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/fogbugz_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/github_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/gitlab_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/google_code_controller.rb | 2 |
6 files changed, 14 insertions, 5 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 663269a0f92..0f401f77fcd 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -25,4 +25,13 @@ class Import::BaseController < ApplicationController current_user.namespace end + + def project_save_error(project) + # Projects::CreateService will set base message if unable to save + if project.errors[:base].present? + project.errors[:base].last + else + project.errors.full_messages.join(', ') + end + end end diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index 77af5fb9c4f..fa31933e778 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -55,7 +55,7 @@ class Import::BitbucketController < Import::BaseController if project.persisted? render json: ProjectSerializer.new.represent(project) else - render json: { errors: project.errors.full_messages }, status: :unprocessable_entity + render json: { errors: project_save_error(project) }, status: :unprocessable_entity end else render json: { errors: 'This namespace has already been taken! Please choose another one.' }, status: :unprocessable_entity diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb index 25ec13b8075..2d665e05ac3 100644 --- a/app/controllers/import/fogbugz_controller.rb +++ b/app/controllers/import/fogbugz_controller.rb @@ -66,7 +66,7 @@ class Import::FogbugzController < Import::BaseController if project.persisted? render json: ProjectSerializer.new.represent(project) else - render json: { errors: project.errors.full_messages }, status: :unprocessable_entity + render json: { errors: project_save_error(project) }, status: :unprocessable_entity end end diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index f67ec4c248b..c9870332c0f 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -48,7 +48,7 @@ class Import::GithubController < Import::BaseController if project.persisted? render json: ProjectSerializer.new.represent(project) else - render json: { errors: project.errors.full_messages }, status: :unprocessable_entity + render json: { errors: project_save_error(project) }, status: :unprocessable_entity end else render json: { errors: 'This namespace has already been taken! Please choose another one.' }, status: :unprocessable_entity diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb index 39e2e9e094b..fccbdbca0f6 100644 --- a/app/controllers/import/gitlab_controller.rb +++ b/app/controllers/import/gitlab_controller.rb @@ -32,7 +32,7 @@ class Import::GitlabController < Import::BaseController if project.persisted? render json: ProjectSerializer.new.represent(project) else - render json: { errors: project.errors.full_messages }, status: :unprocessable_entity + render json: { errors: project_save_error(project) }, status: :unprocessable_entity end else render json: { errors: 'This namespace has already been taken! Please choose another one.' }, status: :unprocessable_entity diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb index 9b26a00f7c7..3bce27e810a 100644 --- a/app/controllers/import/google_code_controller.rb +++ b/app/controllers/import/google_code_controller.rb @@ -92,7 +92,7 @@ class Import::GoogleCodeController < Import::BaseController if project.persisted? render json: ProjectSerializer.new.represent(project) else - render json: { errors: project.errors.full_messages }, status: :unprocessable_entity + render json: { errors: project_save_error(project) }, status: :unprocessable_entity end end |