diff --git a/lib/gitlab/email/handler/base_handler.rb b/lib/gitlab/email/handler/base_handler.rb index e6c2705421d9c5e7900090ce48659c7ef7dd4f7c..4d74e770b918fd96f81d9f82c6c7d2558aab3cd0 100644 --- a/lib/gitlab/email/handler/base_handler.rb +++ b/lib/gitlab/email/handler/base_handler.rb @@ -42,9 +42,12 @@ module Gitlab end.join end - def verify_record!(record, exception, error_title) + def verify_record!(record, exception, name) return if record.persisted? + error_title = + "The #{name} could not be created for the following reasons:" + msg = error_title + record.errors.full_messages.map do |error| "\n\n- #{error}" end.join diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb index 431bd9a8f4efbeb479b5fecba3ada12b4e3c0c14..f8b23d0716590cb236648dc5080ff547e8c8323a 100644 --- a/lib/gitlab/email/handler/create_issue_handler.rb +++ b/lib/gitlab/email/handler/create_issue_handler.rb @@ -22,11 +22,7 @@ module Gitlab validate_permission!(:create_issue) - verify_record!( - create_issue, - InvalidIssueError, - "The issue could not be created for the following reasons:" - ) + verify_record!(create_issue, InvalidIssueError, '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 a9af2f44a81c19c6f4b9bfda083d713215a6042c..e4da6b590fb334a1437e62ce91f7014fd5b3c6cf 100644 --- a/lib/gitlab/email/handler/create_note_handler.rb +++ b/lib/gitlab/email/handler/create_note_handler.rb @@ -19,11 +19,7 @@ module Gitlab raise NoteableNotFoundError unless sent_notification.noteable raise EmptyEmailError if message.blank? - verify_record!( - create_note, - InvalidNoteError, - "The comment could not be created for the following reasons:" - ) + verify_record!(create_note, InvalidNoteError, 'comment') end def author