diff options
author | James Lopez <james@jameslopez.es> | 2016-05-30 19:02:54 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-06-03 04:47:38 +0300 |
commit | b2b2b2f9de1a7d96decbd1e54336ba805a059d9e (patch) | |
tree | 440ac3519afdb1b2f922181012c7f30aa69c3115 /app/services/projects | |
parent | 74849f9783850676274a4e93a1b6335b5bb34f2e (diff) |
fix create service error handling - missing setting import status to failed
Diffstat (limited to 'app/services/projects')
-rw-r--r-- | app/services/projects/create_service.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 6728fabea1e..b73389f0489 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -56,14 +56,14 @@ module Projects after_create_actions if @project.persisted? - @project.add_import_job if @project.import? - + if @project.errors.empty? + @project.add_import_job if @project.import? + else + fail(error: @project.errors.join(', ')) + end @project rescue => e - message = "Unable to save project: #{e.message}" - Rails.logger.error(message) - @project.errors.add(:base, message) if @project - @project + fail(error: e.message) end protected @@ -103,5 +103,19 @@ module Projects end end end + + def fail(error:) + message = "Unable to save project. Error: #{error}" + message << "Project ID: #{@project.id}" if @project && @project.id + + Rails.logger.error(message) + + if @project && @project.import? + @project.errors.add(:base, message) + @project.mark_import_as_failed(message) + end + + @project + end end end |