Skip to content
Snippets Groups Projects
Commit 1f5d5590 authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Merge the places where exceptions could be raised

parent 863d8e5a
No related branches found
No related tags found
1 merge request!3363Implement #3243 New Issue by email
Loading
Loading
@@ -24,6 +24,8 @@ class EmailReceiverWorker
reason = nil
 
case e
when Gitlab::Email::UnknownIncomingEmail
reason = "We couldn't figure out what the email is for."
when Gitlab::Email::SentNotificationNotFoundError
reason = "We couldn't figure out what the email is in reply to. Please create your comment through the web interface."
when Gitlab::Email::ProjectNotFound
Loading
Loading
Loading
Loading
@@ -14,10 +14,11 @@ module Gitlab
end
 
def can_handle?
!!(project_namespace && project)
!!authentication_token
end
 
def execute
raise ProjectNotFound unless project
validate_permission!(:create_issue)
 
verify_record!(
Loading
Loading
Loading
Loading
@@ -6,7 +6,8 @@ module Gitlab
module Handler
class CreateNoteHandler < BaseHandler
def can_handle?
!!(mail_key && sent_notification)
# We want to raise SentNotificationNotFoundError for missing key
!!(mail_key.nil? || mail_key =~ /\A\w+\z/)
end
 
def execute
Loading
Loading
Loading
Loading
@@ -16,6 +16,7 @@ module Gitlab
class NoteableNotFoundError < ProcessingError; end
class InvalidNoteError < ProcessingError; end
class InvalidIssueError < ProcessingError; end
class UnknownIncomingEmail < ProcessingError; end
 
class Receiver
def initialize(raw)
Loading
Loading
@@ -30,11 +31,8 @@ module Gitlab
 
if handler = Handler.for(mail, mail_key)
handler.execute
elsif mail_key =~ %r{/|\+}
# Sent Notification mail_key would not have / or +
raise ProjectNotFound
else
raise SentNotificationNotFoundError
raise UnknownIncomingEmail
end
end
 
Loading
Loading
Loading
Loading
@@ -30,6 +30,14 @@ describe Gitlab::Email::Receiver, lib: true do
)
end
 
context "when we cannot find a capable handler" do
let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "!!!") }
it "raises a UnknownIncomingEmail" do
expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail)
end
end
context "when the recipient address doesn't include a mail key" do
let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment