diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index eac3b30c2..b16f1fcd8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -110,6 +110,10 @@ private def respond_with_post_after_update(post) respond_with(post) do |format| format.html do + if post.warnings.any? + flash[:notice] = post.warnings.full_messages.join(".\n \n") + end + if post.errors.any? @error_message = post.errors.full_messages.join("; ") render :template => "static/error", :status => 500 diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index fa2655d9f..6c4466f57 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -53,7 +53,12 @@ class UploadsController < ApplicationController def create @upload = Upload.create(params[:upload].merge(:server => Socket.gethostname)) - @upload.process! if @upload.errors.empty? + + if @upload.errors.empty? + post = @upload.process! + flash[:notice] = post.warnings.full_messages.join(".\n \n") if post.present? && post.warnings.any? + end + save_recent_tags respond_with(@upload) end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index d0bdfc17e..45af77b23 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -43,5 +43,9 @@ class ApplicationRecord < ActiveRecord::Base end end + def warnings + @warnings ||= ActiveModel::Errors.new(self) + end + include ApiMethods end diff --git a/app/models/upload.rb b/app/models/upload.rb index 4d0704d24..0115f4c46 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -148,6 +148,8 @@ class Upload < ApplicationRecord else update_attribute(:status, "error: " + post.errors.full_messages.join(", ")) end + + post end def process!(force = false) @@ -155,7 +157,7 @@ class Upload < ApplicationRecord return if !force && status =~ /processing|completed|error/ process_upload - create_post_from_upload + post = create_post_from_upload rescue Timeout::Error, Net::HTTP::Persistent::Error => x if @tries > 3 @@ -164,9 +166,11 @@ class Upload < ApplicationRecord @tries += 1 retry end + nil rescue Exception => x update_attributes(:status => "error: #{x.class} - #{x.message}", :backtrace => x.backtrace.join("\n")) + nil ensure delete_temp_file diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 968be757e..3da3aed44 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -112,7 +112,7 @@ <% end %>
"> - <%= flash[:notice] %> + <%= format_text(flash[:notice], inline: true) %>. close