Handle CSV::MalformedCSVError
This commit is contained in:
@@ -46,14 +46,19 @@ class ItemsController < ApplicationController
|
|||||||
@csv_content = params[:csv_content]
|
@csv_content = params[:csv_content]
|
||||||
|
|
||||||
@error_message = ""
|
@error_message = ""
|
||||||
|
@output = []
|
||||||
|
|
||||||
if params[:csv_content] == ""
|
if params[:csv_content] == ""
|
||||||
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
csv_parsed = CSV.parse(params[:csv_content])
|
csv_parsed = CSV.parse(params[:csv_content])
|
||||||
csv_file = ItemsHelper::create_csv(csv_parsed)
|
rescue CSV::MalformedCSVError => er
|
||||||
|
@error_message = "Format of CSV is wrong (#{er.message})"
|
||||||
|
end
|
||||||
|
|
||||||
@output = ""
|
unless csv_parsed.nil?
|
||||||
|
csv_file = ItemsHelper::create_csv(csv_parsed)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ENV["INPUT"] = csv_file.path
|
ENV["INPUT"] = csv_file.path
|
||||||
@@ -74,6 +79,7 @@ class ItemsController < ApplicationController
|
|||||||
ensure
|
ensure
|
||||||
csv_file.unlink
|
csv_file.unlink
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@output = @output.join("<br/>")
|
@output = @output.join("<br/>")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user