diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 1230b9d1dd2..819b1508fbc 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -6,7 +6,7 @@ module Email class Receiver def self.results - @results ||= Enum.new(:unprocessable, :missing, :processed) + @results ||= Enum.new(:unprocessable, :missing, :processed, :error) end attr_reader :body, :reply_key, :email_log @@ -46,6 +46,8 @@ module Email create_reply Email::Receiver.results[:processed] + rescue + Email::Receiver.results[:error] end private diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index d5916d5d178..ad3dcb7b5f3 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -9,6 +9,16 @@ describe Email::Receiver do SiteSetting.stubs(:reply_by_email_address).returns("reply+%{reply_key}@appmail.adventuretime.ooo") end + describe "exception raised" do + it "returns error if it encountered an error processing" do + receiver = Email::Receiver.new("some email") + def receiver.parse_body + raise "ERROR HAPPENED!" + end + expect(receiver.process).to eq(Email::Receiver.results[:error]) + end + end + describe 'invalid emails' do it "returns unprocessable if the message is blank" do expect(Email::Receiver.new("").process).to eq(Email::Receiver.results[:unprocessable])