diff --git a/lib/gitlab/email/handler/base_handler.rb b/lib/gitlab/email/handler/base_handler.rb index 1691fca6465b91d1325637979220e21a5df9375f..b7ed11cb6389e06cdbeccd81a4b0134534d5636e 100644 --- a/lib/gitlab/email/handler/base_handler.rb +++ b/lib/gitlab/email/handler/base_handler.rb @@ -43,17 +43,16 @@ module Gitlab end.join end - def verify_record!(record, exception, name) + def verify_record!(record:, invalid_exception:, record_name:) return if record.persisted? - error_title = - "The #{name} could not be created for the following reasons:" + error_title = "The #{record_name} could not be created for the following reasons:" msg = error_title + record.errors.full_messages.map do |error| "\n\n- #{error}" end.join - raise exception, msg + raise invalid_exception, msg end end end diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb index f8b23d0716590cb236648dc5080ff547e8c8323a..4e6566af8abed30fb7658266c8ec2897802fa23b 100644 --- a/lib/gitlab/email/handler/create_issue_handler.rb +++ b/lib/gitlab/email/handler/create_issue_handler.rb @@ -22,7 +22,10 @@ module Gitlab validate_permission!(:create_issue) - verify_record!(create_issue, InvalidIssueError, 'issue') + verify_record!( + record: create_issue, + invalid_exception: InvalidIssueError, + record_name: 'issue') end def author diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb index e4da6b590fb334a1437e62ce91f7014fd5b3c6cf..6964665122346651fb8ffc2c49d068c7eb2cbc5d 100644 --- a/lib/gitlab/email/handler/create_note_handler.rb +++ b/lib/gitlab/email/handler/create_note_handler.rb @@ -19,7 +19,10 @@ module Gitlab raise NoteableNotFoundError unless sent_notification.noteable raise EmptyEmailError if message.blank? - verify_record!(create_note, InvalidNoteError, 'comment') + verify_record!( + record: create_note, + invalid_exception: InvalidNoteError, + record_name: 'comment') end def author