fix create service error handling - missing setting import status to failed

This commit is contained in:
James Lopez 2016-05-30 18:02:54 +02:00 committed by Robert Speicher
parent 74849f9783
commit b2b2b2f9de

View file

@ -56,14 +56,14 @@ module Projects
after_create_actions if @project.persisted?
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