Commit 0671db52 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent c491f669
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment