From a710d0d8033c84b72e1a6395adfbd6beebf80730 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 6 Mar 2013 06:38:08 -0500 Subject: collect errors --- app/controllers/trigger_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 8e70ef2..5e836c4 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -62,12 +62,14 @@ class TriggerController < ApplicationController def fax if !params[:fax_account_id].blank? fax_account = FaxAccount.where(:id => params[:fax_account_id].to_i).first + errors = Array.new() if fax_account fax_account.fax_documents.where(:state => 'received').each do |fax_document| pdf_file = fax_document.tiff_to_pdf if !pdf_file + errors << "#{fax_document.tiff} cound not be converted" fax_document.state = 'unsuccessful' fax_document.save next @@ -89,15 +91,21 @@ class TriggerController < ApplicationController File.delete(pdf_file) rescue => e logger.error "PDF fax file could not be deleted: #{pdf_file} => #{e.inspect}" + errors << "#{pdf_file} cound not be deleted" end fax_document.save fax_document.render_thumbnails else + errors << "#{fax_document.id} cound not be saved" fax_document.state = 'unsuccessful' fax_document.save end end - + else + errors << "fax_account=#{params[:fax_account_id]} not found" + end + + if errors.count == 0 render( :status => 200, :layout => false, @@ -105,11 +113,11 @@ class TriggerController < ApplicationController :text => "", ) else - render( - :status => 404, + render( + :status => 501, :layout => false, :content_type => 'text/plain', - :text => "", + :text => "", ) end end -- cgit v1.2.3