fix create service error handling - missing setting import status to failed
This commit is contained in:
parent
74849f9783
commit
b2b2b2f9de
1 changed files with 20 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue